:root{
  --bg: #b7d5ac;
  --panel: #f3f3f3;
  --card: #ffffff;

  --text: #0d0f12;
  --muted: #7b8088;
  --line: rgba(17, 20, 26, .08);

  --green: #9bf4a5;
  --green-2: #7fe98d;
  --green-ink: #0b2b12;

  --shadow: 0 18px 48px rgba(0,0,0,.10);
  --shadow-soft: 0 10px 30px rgba(0,0,0,.06);

  --r-xl: 28px;
  --r-lg: 22px;
  --r-md: 18px;
  --r-sm: 14px;

  --gap: 18px;
  --max: 1260px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(1000px 520px at 15% 0%, rgba(255,255,255,.35) 0%, rgba(255,255,255,0) 55%),
    radial-gradient(900px 520px at 85% 100%, rgba(255,255,255,.35) 0%, rgba(255,255,255,0) 60%),
    var(--bg);
  color: var(--text);
  padding: 26px;
}

a{ color: inherit; text-decoration: none; }
button,input{ font: inherit; }

.bg{
  max-width: var(--max);
  margin: 0 auto;
}

.app{
  background: var(--panel);
  border-radius: var(--r-xl);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: var(--shadow);
  padding: 18px;
  overflow: hidden;
}

/* Topbar */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
}

.top-left{
  display:flex;
  align-items:center;
  gap: 16px;
  min-width: 520px;
}

.logo{
  display:flex;
  align-items:center;
  gap: 10px;
  font-weight: 800;
}
.logo-mark{
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255,255,255,.85);
  display:grid;
  place-items:center;
  border: 1px solid var(--line);
  color: #18c45a;
}
.logo-mark svg{ width: 22px; height: 22px; }
.logo-text{ font-size: 18px; letter-spacing:-.02em; }

.nav{
  display:flex;
  align-items:center;
  gap: 8px;
  padding: 6px;
  background: rgba(255,255,255,.55);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.nav-link{
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 600;
  color: rgba(13, 15, 18, .72);
  white-space: nowrap;
}
.nav-link--icon{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
}
.nav-link--icon .nav-ic svg{
  width: 22px;
  height: 22px;
  display: block;
}
.nav-link:hover{ background: rgba(0,0,0,.04); }
.nav-link.is-active{
  background: var(--green);
  color: rgba(13, 15, 18, .92);
  box-shadow: 0 10px 20px rgba(155,244,165,.35);
}

.nav-toggle{
  display: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  font: inherit;
  touch-action: manipulation;
}
.nav-backdrop{
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(13, 15, 18, .38);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.top-right{
  display:flex;
  align-items:center;
  gap: 10px;
}

.search{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  min-width: 320px;
  background: rgba(255,255,255,.75);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.search-ic{
  width: 18px;
  height: 18px;
  color: rgba(13, 15, 18, .55);
  display:grid;
  place-items:center;
}
.search-ic svg{ width: 18px; height: 18px; }
.search input{
  border:0;
  outline:0;
  background: transparent;
  width: 100%;
  color: rgba(13, 15, 18, .85);
}
.search input::placeholder{ color: rgba(13, 15, 18, .45); }

.icon-btn{
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.75);
  display:grid;
  place-items:center;
  cursor:pointer;
}
.icon-btn svg{ width: 20px; height: 20px; color: rgba(13, 15, 18, .62); }
.icon-btn:hover{ background: rgba(255,255,255,.95); box-shadow: var(--shadow-soft); }

/* Main header */
.main{ padding: 14px 6px 6px; }
.welcome{ padding: 10px 6px 16px; }
.kicker{
  color: rgba(13,15,18,.55);
  font-weight: 500;
  margin-bottom: 8px;
}
.title{
  margin: 0;
  font-size: clamp(32px, 3.2vw, 44px);
  letter-spacing: -0.04em;
}
.welcome-sub{
  margin-top: 8px;
  max-width: 72ch;
  color: rgba(13,15,18,.55);
  font-weight: 400;
  line-height: 1.35;
}
.wave{ font-size: .95em; }

/* Grid */
.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--gap);
  align-items: stretch;
}

/* Cards */
.card{
  background: var(--card);
  border: 1px solid rgba(17, 20, 26, .06);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
}

.card-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 16px 16px 0;
}
.card-label{
  font-weight: 600;
  color: rgba(13,15,18,.55);
}
.mini-action{
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display:grid;
  place-items:center;
  background: rgba(0,0,0,.03);
  border: 1px solid rgba(0,0,0,.05);
}
.mini-action svg{ width: 18px; height: 18px; color: rgba(13,15,18,.65); }

/* KPI (stesso stile delle card tipo Total Task) */
.kpi{ padding-bottom: 14px; }
.kpi-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 16px 0;
  gap: 12px;
}
.kpi-value{
  font-size: 44px;
  font-weight: 800;
  letter-spacing:-.03em;
}
.kpi-value--currency{
  font-size: clamp(26px, 3.6vw, 38px);
  letter-spacing: -0.025em;
}
.kpi-ic{
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(155,244,165,.32);
  border: 1px solid rgba(120,235,140,.4);
  color: rgba(18, 110, 50, .88);
}
.kpi-ic svg{
  width: 26px;
  height: 26px;
}

/* Layout mapping */
.kpi:nth-child(1){ grid-column: 1 / span 3; grid-row: 1; }
.kpi:nth-child(2){ grid-column: 4 / span 3; grid-row: 1; }
.kpi:nth-child(3){ grid-column: 7 / span 3; grid-row: 1; }
.kpi:nth-child(4){ grid-column: 10 / span 3; grid-row: 1; }

.chart{ grid-column: 1 / -1; grid-row: 2; }
.tasks-intro{ grid-column: 1 / -1; grid-row: 3; }
.table--tasks{ grid-column: 1 / span 6; grid-row: 4; }
.table--appts{ grid-column: 7 / span 6; grid-row: 4; }
.table--unpaid{ grid-column: 1 / span 6; grid-row: 5; }
.ai{ grid-column: 7 / span 6; grid-row: 5; }
/* Secondo blocco intro: stesso stile ma riga dedicata sotto Fatture + AI */
.tasks-intro.tasks-intro--bottom{
  grid-column: 1 / -1;
  grid-row: 6;
}

.tasks-intro{
  padding: 0;
  margin: 4px 0 0;
  border-radius: 18px;
  border: 1px solid rgba(0,0,0,.06);
  background:
    radial-gradient(520px 220px at 0% 0%, rgba(155,244,165,.22) 0%, rgba(155,244,165,0) 62%),
    rgba(0,0,0,.012);
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}
.tasks-intro::before{
  content:"";
  position:absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: rgba(155,244,165,.95);
}
.tasks-intro-title{
  padding: 14px 16px 0 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-size: 22px;
  color: rgba(13,15,18,.92);
}
.tasks-intro-sub{
  padding: 6px 16px 14px 18px;
  margin-top: 0;
  font-weight: 650;
  color: rgba(13,15,18,.62);
}

/* Chart card */
.card-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 16px 16px 0;
}
.h{ font-weight: 800; letter-spacing:-.02em; }
.sub{ margin-top: 4px; font-size: 12px; color: rgba(13,15,18,.55); }
.chip{
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  font-weight: 600;
  cursor:pointer;
  display:flex;
  align-items:center;
  gap: 8px;
  color: rgba(13,15,18,.75);
}
.chev-sm svg{ width: 16px; height: 16px; color: rgba(13,15,18,.55); }

.bar-chart{
  margin: 12px 16px 16px;
  border-radius: var(--r-md);
  background: rgba(0,0,0,.015);
  border: 1px solid rgba(0,0,0,.04);
  padding: 12px;
  height: 340px;
  display:grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  gap: 8px;
  min-height: 0;
}
.bar-legend{
  display:flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px 18px;
  padding: 0 4px 2px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(13,15,18,.62);
}
.bar-legend-item{
  display:inline-flex;
  align-items:center;
  gap: 7px;
}
.bar-legend-swatch{
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}
.bar-legend-swatch--incassi{
  background: linear-gradient(180deg, rgba(155,244,165,.98), rgba(120,235,140,.92));
  border: 1px solid rgba(0,0,0,.1);
}
.bar-legend-swatch--fatturato{
  background: linear-gradient(180deg, rgba(0,0,0,.11), rgba(0,0,0,.2));
  border: 1px solid rgba(0,0,0,.12);
}
.bar-chart .bars{
  /* --scale-max = massimo tra tutti gli importi (--val) nel markup; altezza barre ∝ --val */
  --scale-max: 5120;
  --bar-max-h: 188px;
  position:relative;
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: stretch;
  gap: 5px;
  padding: 8px 4px 10px;
  min-height: 0;
  border-radius: 14px;
  background:
    linear-gradient(180deg, transparent 0 24%, rgba(0,0,0,.05) 24% 25%, transparent 25% 49%,
                            rgba(0,0,0,.05) 49% 50%, transparent 50% 74%,
                            rgba(0,0,0,.05) 74% 75%, transparent 75% 100%);
}
.bar-month{
  display:flex;
  flex-direction:column;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.bar-pair{
  flex: 1 1 0;
  min-height: 0;
  display:flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
}
.bar-col{
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display:flex;
  flex-direction:column;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}
.bar-euro{
  font-size: clamp(7px, 1.65vw, 10px);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: rgba(13,15,18,.78);
  text-align: center;
  line-height: 1.1;
  max-width: 100%;
}
.bar-mese{
  flex-shrink: 0;
  text-align: center;
  font-size: clamp(9px, 1.05vw, 11px);
  font-weight: 700;
  color: rgba(13,15,18,.45);
  padding-top: 6px;
}
.bar{
  width: 100%;
  max-width: 28px;
  margin: 0 auto;
  border-radius: 10px;
  background: rgba(0,0,0,.07);
  flex-shrink: 0;
}
.bar.bar--incassi,
.bar.bar--fatturato{
  height: calc(var(--val) / var(--scale-max) * var(--bar-max-h));
  min-height: 4px;
  max-height: var(--bar-max-h);
}
.bar--incassi{
  background: linear-gradient(180deg, rgba(155,244,165,.98), rgba(120,235,140,.9));
  box-shadow: 0 6px 14px rgba(155,244,165,.22);
  border: 1px solid rgba(0,0,0,.06);
}
.bar--fatturato{
  background: linear-gradient(180deg, rgba(0,0,0,.1), rgba(0,0,0,.2));
  border: 1px solid rgba(0,0,0,.1);
}

/* Table card */
.table{ padding-bottom: 10px; }
.kebab{
  width: 38px; height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  cursor:pointer;
}
.kebab:hover{ background: rgba(0,0,0,.04); }
.t-head, .t-row{
  display:grid;
  grid-template-columns: 1.5fr 1.2fr .7fr 1fr 1fr;
  gap: 12px;
  align-items:center;
  padding: 12px 16px;
}
.t-head{
  margin-top: 10px;
  color: rgba(13,15,18,.45);
  font-weight: 700;
  font-size: 12px;
}
.t-row{
  border-top: 1px solid rgba(0,0,0,.05);
  font-size: 13px;
}
.t-name{ display:flex; gap: 10px; align-items:center; }
.pimg{
  width: 34px; height: 34px; border-radius: 999px;
  display:grid; place-items:center;
  border: 1px solid rgba(0,0,0,.06);
  background: rgba(0,0,0,.03);
  font-weight: 900;
}
.nm{ font-weight: 800; }
.un{ font-size: 12px; color: rgba(13,15,18,.45); margin-top: 2px; }
.t-cell{ color: rgba(13,15,18,.70); }

.status{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  font-weight: 700;
  color: rgba(13,15,18,.70);
}
.sb{
  width: 28px; height: 10px;
  border-radius: 999px;
  display:inline-block;
  background: rgba(0,0,0,.10);
}
.status.ok .sb{ background: rgba(155,244,165,.95); }
.status.warn .sb{ background: rgba(255, 90, 90, .85); }

.receipt{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  height: 34px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(155,244,165,.55);
  background: rgba(155,244,165,.28);
  font-weight: 800;
  font-size: 12px;
}

/* AI card */
.ai{ padding: 12px 12px 14px; }
.ai-top{ padding: 6px 4px 0; }
.chip-soft{
  background: rgba(0,0,0,.02);
  border-color: rgba(0,0,0,.06);
}
.ai-badge{
  width: 14px; height: 14px;
  border-radius: 999px;
  background: rgba(155,244,165,.95);
  box-shadow: 0 0 0 4px rgba(155,244,165,.25);
}
.ai-body{
  margin-top: 10px;
  padding: 10px 10px 0;
  text-align:center;
}
.ai-orb{
  width: 74px; height: 74px;
  margin: 6px auto 10px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.7), transparent 45%),
    radial-gradient(circle at 70% 70%, rgba(0,0,0,.10), transparent 55%),
    rgba(155,244,165,.85);
  box-shadow: 0 18px 35px rgba(155,244,165,.35);
}
.ai-greet{ font-weight: 800; }
.ai-q{
  margin-top: 4px;
  font-weight: 900;
  letter-spacing:-.02em;
}
.mint{ color: rgba(22, 165, 78, .95); }

.ai-input{
  margin-top: 12px;
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,.06);
  background: rgba(0,0,0,.02);
}
.sparkle{ color: rgba(13,15,18,.55); }
.ai-input input{
  border:0; outline:0; background: transparent;
  width: 100%;
}
.ai-input input::placeholder{ color: rgba(13,15,18,.45); }
.send{
  width: 34px; height: 34px;
  border-radius: 12px;
  border: 0;
  background: rgba(155,244,165,.95);
  font-weight: 900;
  cursor:pointer;
}

.ai-actions{
  margin-top: 12px;
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.mini-card{
  border: 1px solid rgba(0,0,0,.06);
  background: rgba(0,0,0,.01);
  border-radius: 14px;
  padding: 10px 8px;
  cursor:pointer;
  text-align:left;
}
.mini-ic{ font-size: 16px; }
.mini-t{ margin-top: 8px; font-weight: 900; font-size: 11px; color: rgba(13,15,18,.75); }

/* Responsive */
@media (max-width: 1200px){
  .top-left{ min-width: auto; flex-wrap: wrap; }
  .search{ min-width: 240px; }
}
@media (max-width: 980px){
  body{ padding: 14px; }
  .topbar{ flex-wrap: wrap; }
  .top-right{ width: 100%; justify-content: space-between; }
  .search{ flex: 1; min-width: 0; }
  .grid{ grid-template-columns: repeat(6, 1fr); }
  .kpi:nth-child(1){ grid-column: 1 / span 3; grid-row: 1; }
  .kpi:nth-child(2){ grid-column: 4 / span 3; grid-row: 1; }
  .kpi:nth-child(3){ grid-column: 1 / span 3; grid-row: 2; }
  .kpi:nth-child(4){ grid-column: 4 / span 3; grid-row: 2; }
  .chart{ grid-column: 1 / -1; grid-row: 3; }
  .tasks-intro{ grid-column: 1 / -1; grid-row: 4; }
  .table--tasks{ grid-column: 1 / span 3; grid-row: 5; }
  .table--appts{ grid-column: 4 / span 3; grid-row: 5; }
  .table--unpaid{ grid-column: 1 / span 3; grid-row: 6; }
  .ai{ grid-column: 4 / span 3; grid-row: 6; }
  .tasks-intro.tasks-intro--bottom{ grid-row: 7; }
}
@media (max-width: 900px){
  html.nav-open .app{
    overflow: visible;
  }
  .top-left{
    min-width: 0;
    flex: 1;
    align-items: center;
  }
  .nav-toggle{
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.75);
    cursor: pointer;
    margin-left: auto;
    z-index: 100;
    flex-shrink: 0;
    box-shadow: var(--shadow-soft);
  }
  .nav-toggle:hover{
    background: rgba(255,255,255,.95);
  }
  .nav-toggle-lines{
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 18px;
  }
  .nav-toggle-lines span{
    display: block;
    height: 2px;
    border-radius: 1px;
    background: rgba(13, 15, 18, .72);
    transition: transform .2s ease, opacity .15s ease;
    transform-origin: center;
  }
  html.nav-open .nav-toggle-lines span:nth-child(1){
    transform: translateY(7px) rotate(45deg);
  }
  html.nav-open .nav-toggle-lines span:nth-child(2){
    opacity: 0;
  }
  html.nav-open .nav-toggle-lines span:nth-child(3){
    transform: translateY(-7px) rotate(-45deg);
  }
  .nav{
    position: fixed;
    top: 0;
    right: 0;
    width: min(300px, 88vw);
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: calc(22px + env(safe-area-inset-top, 0px)) 16px 28px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    border-radius: 0;
    border: 0;
    border-left: 1px solid var(--line);
    background: rgba(255,255,255,.97);
    box-shadow: -16px 0 48px rgba(0,0,0,.14);
    z-index: 90;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(100%);
    transition: transform .28s ease, visibility .28s;
    visibility: hidden;
    pointer-events: none;
  }
  html.nav-open .nav{
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }
  .nav-link{
    display: flex;
    justify-content: flex-start;
    white-space: normal;
    text-align: left;
  }
  .nav-link--icon{
    justify-content: flex-start;
  }
}
@media (max-width: 640px){
  .kpi:nth-child(1){ grid-column: 1 / -1; grid-row: 1; }
  .kpi:nth-child(2){ grid-column: 1 / -1; grid-row: 2; }
  .kpi:nth-child(3){ grid-column: 1 / -1; grid-row: 3; }
  .kpi:nth-child(4){ grid-column: 1 / -1; grid-row: 4; }
  .chart{ grid-column: 1 / -1; grid-row: 5; }
  .tasks-intro{ grid-column: 1 / -1; grid-row: 6; }
  .table--tasks{ grid-column: 1 / -1; grid-row: 7; }
  .table--appts{ grid-column: 1 / -1; grid-row: 8; }
  .table--unpaid{ grid-column: 1 / -1; grid-row: 9; }
  .ai{ grid-column: 1 / -1; grid-row: 10; }
  .tasks-intro.tasks-intro--bottom{ grid-row: 11; }
  .t-head{ display:none; }
  .t-row{ grid-template-columns: 1fr 1fr; grid-auto-rows: auto; }
  .t-row > :nth-child(2),
  .t-row > :nth-child(3),
  .t-row > :nth-child(4),
  .t-row > :nth-child(5){ grid-column: 1 / -1; }
  .ai-actions{ grid-template-columns: 1fr; }
}