/* ============================================================
   ProfitOS UI v2 — Production Enterprise CSS
   REGOLE FERREE:
   - Tutte le variabili esistenti INVARIATE
   - Tutti i nomi di classe INVARIATI
   - Solo font aggiornato a Inter (Verdana come fallback)
   - Nuove classi AGGIUNTE in fondo (toast, skeleton, trend, mobile)
   - Zero breaking changes
   ============================================================ */

/* Inter font — caricato prima di tutto */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ============================================================
   VARIABILI — INVARIATE rispetto alla v1
   ============================================================ */
:root{
  --bg-main: #020617;
  --bg-soft: #081121;
  --bg-card: #0f172a;
  --bg-elevated: #1e293b;
  --bg-hover: #243244;
  --bg-input: #f8fafc;

  --text-main: #ffffff;
  --text-secondary: #dbe4ee;
  --text-muted: #9fb0c4;
  --text-dark: #04130a;

  --border-soft: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.24);

  --ai-green: #22c55e;
  --ai-green-hover: #16a34a;
  --ai-green-soft: rgba(34, 197, 94, 0.14);
  --ai-glow: rgba(34, 197, 94, 0.35);

  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-soft: #7f1d1d;
  --info: #38bdf8;

  --success-bg: rgba(34, 197, 94, 0.12);
  --warning-bg: rgba(245, 158, 11, 0.14);
  --danger-bg: rgba(239, 68, 68, 0.14);
  --info-bg: rgba(56, 189, 248, 0.14);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-soft: 0 10px 30px rgba(0,0,0,0.25);
  --shadow-card: 0 12px 34px rgba(0,0,0,0.28);
  --shadow-glow: 0 0 18px var(--ai-glow);

  --sidebar-width: 260px;

  /* ── NUOVE variabili v2 (aggiunte, non sostituiscono niente) ── */
  --transition-fast: 0.18s ease;
  --transition-medium: 0.28s ease;
  --font-primary: 'Inter', Verdana, Geneva, Tahoma, sans-serif;
}

/* ============================================================
   BASE — stesso della v1, solo font aggiornato
   ============================================================ */
*{
  box-sizing: border-box;
}

html, body{
  margin: 0;
  padding: 0;
}

body{
  background: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-primary);
  line-height: 1.55;
  font-size: 16px;
}

a{
  color: inherit;
}

img{
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea{
  font: inherit;
  font-family: var(--font-primary);
}

h1, h2, h3, h4, h5, h6{
  margin-top: 0;
  color: var(--text-main);
  font-family: var(--font-primary);
}

h1{
  font-size: 38px;
  font-weight: 800;
  line-height: 1.15;
}

h2{
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

h3{
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
}

p{
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.7;
}

.small{
  font-size: 14px;
  color: var(--text-secondary);
}

.muted{
  color: var(--text-muted);
}

.section-title,
.sectionTitle{
  margin: 0 0 12px 0;
  font-size: 26px;
  line-height: 1.2;
}

/* ============================================================
   LAYOUT — INVARIATO
   ============================================================ */
.page-shell{
  min-height: 100vh;
  background: var(--bg-main);
}

.container{
  padding: 32px;
}

.with-sidebar .container,
.container.with-sidebar{
  margin-left: var(--sidebar-width);
}

.grid{
  display: grid;
  gap: 18px;
}

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

.grid-3{
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4{
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two-col{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* ============================================================
   SIDEBAR — INVARIATA
   ============================================================ */
#sidebar{
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  z-index: 1000;
}

.sidebar{
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-main);
  border-right: 1px solid var(--border-soft);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sidebar .section{
  margin-top: 15px;
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar .menu a{
  display: block;
  padding: 12px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar .menu a:hover{
  background: var(--bg-elevated);
  color: var(--text-main);
}

.sidebar .logout{
  display: block;
  text-align: center;
  background: var(--danger);
  color: white;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-decoration: none;
  margin-bottom: 14px;
}

.sidebar-footer{
  color: #64748b;
  font-size: 12px;
}

/* ── v2: Active nav link (classe aggiunta via JS, non rompe niente) ── */
.sidebar .menu a.nav-active{
  background: var(--ai-green-soft);
  color: var(--ai-green);
  font-weight: 600;
  border-left: 3px solid var(--ai-green);
  padding-left: 9px;
}

/* ============================================================
   CARDS — INVARIATE
   ============================================================ */
.card{
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-soft);
}

.card-soft{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.panel{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.ai,
.ai-box,
.insight{
  background: #022c22;
  border-left: 6px solid var(--ai-green);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.alertBox,
.alert-danger{
  background: #3b0a0a;
  border-left: 6px solid var(--danger);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.priority-box{
  background: #450a0a;
  border-left: 6px solid var(--danger);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.recovery-box{
  background: #022c22;
  border-left: 6px solid var(--ai-green);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.info-box{
  background: var(--info-bg);
  border-left: 6px solid var(--info);
  border-radius: var(--radius-lg);
  padding: 18px;
}

/* ============================================================
   KPI — INVARIATE + v2 trend badge
   ============================================================ */
.kpi{
  font-size: 34px;
  font-weight: 800;
  margin-top: 8px;
  line-height: 1.15;
}

.kpi-sub{
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.6;
}

.kpi-title{
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 8px;
}

.kpi-value{
  font-size: 38px;
  font-weight: 800;
  line-height: 1.15;
}

/* ── v2: Trend badge sotto i KPI (classe nuova, non tocca .kpi) ── */
.kpi-trend{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  margin-top: 6px;
}

.kpi-trend.up{
  background: var(--success-bg);
  color: var(--ai-green);
}

.kpi-trend.down{
  background: var(--danger-bg);
  color: var(--danger);
}

.kpi-trend.flat{
  background: var(--warning-bg);
  color: var(--warning);
}

/* ============================================================
   BADGES — INVARIATI
   ============================================================ */
.badge{
  display: inline-block;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  color: var(--text-secondary);
  font-size: 13px;
  margin-right: 8px;
  margin-top: 8px;
}

.badge-success{
  background: var(--success-bg);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.25);
}

.badge-warning{
  background: var(--warning-bg);
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.25);
}

.badge-danger{
  background: var(--danger-bg);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.25);
}

.badge-info{
  background: var(--info-bg);
  color: #bae6fd;
  border-color: rgba(56, 189, 248, 0.25);
}

.hero-metrics span{
  display: inline-block;
  margin-right: 10px;
  margin-top: 8px;
  padding: 7px 11px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
}

.mini-stat{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 15px;
  margin-top: 10px;
}

/* ============================================================
   BUTTONS — INVARIATI
   ============================================================ */
button,
.btn{
  display: inline-block;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
  font-size: 15px;
}

button:hover,
.btn:hover{
  filter: brightness(1.03);
}

button:active,
.btn:active{
  transform: translateY(1px);
}

.primary,
.btn-primary{
  background: var(--ai-green);
  color: var(--text-dark);
  font-weight: 700;
}

.primary:hover,
.btn-primary:hover{
  background: var(--ai-green-hover);
}

.secondary,
.btn-secondary{
  background: #334155;
  color: white;
}

.warning,
.btn-warning{
  background: var(--warning);
  color: #1f1300;
  font-weight: 700;
}

.danger,
.btn-danger{
  background: var(--danger);
  color: white;
  font-weight: 700;
}

.ghost,
.btn-ghost{
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}

/* ── v2: Loading state per pulsanti (classe aggiunta via JS) ── */
button.loading,
.btn.loading{
  opacity: 0.7;
  cursor: not-allowed;
  pointer-events: none;
  position: relative;
}

button.loading::after,
.btn.loading::after{
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

/* ============================================================
   FORMS — INVARIATE
   ============================================================ */
input,
select,
textarea{
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 13px;
  box-sizing: border-box;
  font-size: 15px;
}

.dark-input{
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
}

.light-input,
input:not(.dark-input),
select:not(.dark-input),
textarea:not(.dark-input){
  background: var(--bg-input);
  color: #0f172a;
}

/* ── v2: Validation inline (classi nuove, non rompono niente) ── */
input.input-valid,
select.input-valid,
textarea.input-valid{
  border: 2px solid var(--ai-green) !important;
}

input.input-error,
select.input-error,
textarea.input-error{
  border: 2px solid var(--danger) !important;
}

.field-error-msg{
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
  display: block;
}

label{
  display: block;
  margin-top: 12px;
  margin-bottom: 7px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 700;
}

/* ============================================================
   LIST / LOG / TASK — INVARIATI
   ============================================================ */
.log-row,
.task-item,
.action-item,
.insight-item,
.list-item{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  margin-top: 10px;
}

.log-row{
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.log-main{
  flex: 1;
}

.log-action,
.action-title{
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
  line-height: 1.4;
}

.log-meta,
.action-reason{
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

.log-profit{
  font-weight: 800;
  font-size: 19px;
  min-width: 110px;
  text-align: right;
}

.task{
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 15px;
  border-left: 6px solid var(--ai-green);
}

.task.high{
  border-left-color: var(--danger);
}

.task.medium{
  border-left-color: var(--warning);
}

/* ============================================================
   CHAT / NOTES — INVARIATI
   ============================================================ */
.chat,
.notes{
  background: #000000;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 15px;
  overflow-y: auto;
}

.msg-user{
  color: #93c5fd;
  margin: 0 0 10px 0;
  line-height: 1.7;
}

.msg-bot{
  color: #86efac;
  margin: 0 0 14px 0;
  line-height: 1.7;
}

.note{
  margin-bottom: 10px;
  padding: 12px;
  background: #111827;
  border-left: 4px solid var(--ai-green);
  border-radius: 6px;
  line-height: 1.7;
}

.note-high{
  border-left-color: var(--danger);
}

.note-medium{
  border-left-color: var(--warning);
}

/* ============================================================
   DTN / HERO / HEADER / FOOTER — INVARIATI
   ============================================================ */
.dtn{
  margin: 50px auto;
  width: 70%;
  background: var(--bg-card);
  border-left: 6px solid var(--danger);
  padding: 25px;
  border-radius: var(--radius-lg);
  font-size: 22px;
  box-shadow: var(--shadow-soft);
}

.dtn-main{
  background: var(--bg-card);
  border: 1px solid rgba(34,197,94,0.25);
  padding: 22px;
  border-radius: var(--radius-lg);
}

.dtn-headline{
  font-size: 30px;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.2;
}

.dtn-subtitle{
  font-size: 19px;
  color: #e2e8f0;
  margin-bottom: 8px;
  line-height: 1.6;
}

.dtn-reason{
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

.header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
}

.brand{
  font-size: 36px;
  font-weight: 900;
  color: var(--ai-green);
  text-shadow: 0 0 15px var(--ai-glow);
}

.nav{
  display: flex;
  gap: 12px;
}

.nav a{
  padding: 8px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
}

.hero{
  text-align: center;
  margin-top: 60px;
}

.hero h1{
  font-size: 56px;
  line-height: 1.1;
}

.highlight{
  color: var(--ai-green);
}

.subtitle{
  margin-top: 25px;
  font-size: 25px;
  color: #cbd5f5;
  line-height: 1.6;
}

.stats{
  display: flex;
  justify-content: center;
  gap: 80px;
  margin-top: 40px;
}

.stat h2{
  color: var(--ai-green);
  font-size: 38px;
}

.footer{
  margin-top: 60px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   UTILITY — INVARIATE
   ============================================================ */
.good{ color: var(--success); }
.warn{ color: var(--warning); }
.bad{ color: var(--danger); }
.info{ color: var(--info); }

.hidden{ display:none !important; }
.center{ text-align:center; }
.w-full{ width:100%; }

/* ============================================================
   ▼▼▼ SEZIONI NUOVE v2 — Solo aggiunte, zero conflitti ▼▼▼
   ============================================================ */

/* ── TOAST SYSTEM ── */
/* Uso: showToast("Messaggio", "success"|"error"|"warning"|"info") */
.toast-container{
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  font-weight: 500;
  min-width: 260px;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  pointer-events: all;
  animation: toast-in 0.3s ease forwards;
  backdrop-filter: blur(8px);
}

.toast.toast-success{
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

.toast.toast-error{
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.toast.toast-warning{
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.toast.toast-info{
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd;
}

.toast.toast-hide{
  animation: toast-out 0.3s ease forwards;
}

/* ── SKELETON LOADING ── */
/* Uso: <div class="skeleton skeleton-card"></div> */
.skeleton{
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--radius-md);
}

.skeleton-card{
  height: 120px;
  width: 100%;
  margin-bottom: 12px;
}

.skeleton-line{
  height: 16px;
  width: 100%;
  margin-bottom: 10px;
  border-radius: 4px;
}

.skeleton-line.w-75{ width: 75%; }
.skeleton-line.w-50{ width: 50%; }
.skeleton-line.w-33{ width: 33%; }

.skeleton-kpi{
  height: 80px;
  border-radius: var(--radius-lg);
}

/* ── MOBILE SIDEBAR HAMBURGER ── */
/* Pulsante aggiunto via JS — non tocca HTML esistente */
.sidebar-hamburger{
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1100;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-main);
  line-height: 1;
}

.sidebar-overlay{
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 999;
  backdrop-filter: blur(2px);
}

/* ── ANIMATIONS ── */
@keyframes shimmer{
  0%  { background-position: -200% 0; }
  100%{ background-position:  200% 0; }
}

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

@keyframes toast-in{
  from{ opacity: 0; transform: translateY(16px) scale(0.96); }
  to  { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out{
  from{ opacity: 1; transform: translateY(0); }
  to  { opacity: 0; transform: translateY(8px); }
}

@keyframes count-up{
  from{ opacity: 0; transform: translateY(6px); }
  to  { opacity: 1; transform: translateY(0); }
}

/* ── FADE TRANSITION (compatibile con loadPage esistente) ── */
.fade{
  animation: fade-in 0.25s ease;
}

@keyframes fade-in{
  from{ opacity: 0; transform: translateY(6px); }
  to  { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   RESPONSIVE — INVARIATO + mobile hamburger
   ============================================================ */
@media (max-width: 1100px){
  .stats{
    gap: 30px;
    flex-wrap: wrap;
  }
}

@media (max-width: 900px){
  .two-col,
  .grid-2,
  .grid-3,
  .grid-4{
    grid-template-columns: 1fr;
  }

  .with-sidebar .container,
  .container.with-sidebar,
  .container{
    margin-left: 0;
    padding: 20px;
  }

  /* ── v2: Sidebar slide-in su mobile (sostituisce position:relative) ── */
  #sidebar{
    position: fixed;
    width: var(--sidebar-width);
    height: 100vh;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
  }

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

  .sidebar{
    width: var(--sidebar-width);
    height: 100vh;
    position: relative;
    overflow-y: auto;
  }

  .sidebar-hamburger{
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-overlay.overlay-visible{
    display: block;
  }

  .header{
    padding: 20px;
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }

  .hero h1{
    font-size: 40px;
  }

  .subtitle{
    font-size: 21px;
  }

  .dtn{
    width: calc(100% - 40px);
  }

  .toast-container{
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  .toast{
    max-width: 100%;
  }
}
