/* LEO Assistant — stile Pecus Chain (stessi token di dashboard_assicurazione.html) */
:root{
  --bg:#FAFAF5; --surface:#FFFFFF; --border:#DBD8D5; --line:#EDEAE4;
  --ink:#362A1F; --ink-muted:#8B6C4F;
  --brand:#4A6007; --brand-soft:#6B8E23; --brand-tint:#A9C84D; --brand-wash:#EEF1E1;
  --tech:#1B4B66; --tech-soft:#407491; --tech-tint:#9FBCCC; --tech-wash:#E7EEF1;
  --gold:#BA7D35; --gold-wash:#FBF0DF;
  --ok:#6B8E23; --warn:#E0A126; --crit:#C2452D; --crit-wash:#F7E3DE;
  --shadow:0 1px 2px rgba(54,42,31,.05), 0 10px 28px -14px rgba(54,42,31,.22);
  --shadow-sm:0 1px 2px rgba(54,42,31,.06);
  --radius-lg:20px; --radius:14px; --radius-sm:9px;
  --font:'Raleway', ui-sans-serif, system-ui, sans-serif;
  color-scheme:light;
}
*{box-sizing:border-box;}
html,body{height:100%;}
body{margin:0; background:var(--bg); color:var(--ink); font-family:var(--font); font-size:14px; line-height:1.5;
  -webkit-font-smoothing:antialiased; font-feature-settings:"lnum" 1,"tnum" 1; font-variant-numeric:lining-nums tabular-nums;}
button{font-family:inherit; font-size:inherit; color:inherit; background:none; border:0; cursor:pointer; padding:0;}
textarea,input{font-family:inherit; font-size:inherit; color:inherit;}
:focus-visible{outline:2px solid var(--tech); outline-offset:2px; border-radius:6px;}
@media (prefers-reduced-motion:reduce){*{transition:none !important; animation:none !important;}}

:root{--nav-h:56px;}

/* ============ Barra di navigazione ============ */
.topnav{height:var(--nav-h); display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:16px; padding:0 20px;
  background:var(--surface); border-bottom:1px solid var(--border); position:sticky; top:0; z-index:40;}
.topnav .brand{display:flex; align-items:center; gap:10px; height:34px; justify-self:start;}
.topnav .brand .pictogram{height:32px; width:auto;}
.topnav .brand .wordmark{height:24px; width:auto;}
.topnav .tabs{display:flex; align-items:center; gap:4px; justify-self:center; background:var(--bg);
  border:1px solid var(--line); border-radius:12px; padding:3px;}
.topnav .tab{display:inline-flex; align-items:center; gap:7px; padding:8px 14px; border-radius:10px; font-size:13px; font-weight:700;
  color:var(--ink-muted); text-decoration:none; transition:background .15s, color .15s;}
.topnav .tab:hover{background:var(--surface); color:var(--ink);}
.topnav .tab.active{background:var(--surface); color:var(--brand); box-shadow:var(--shadow-sm);}
.topnav .nav-right{justify-self:end; display:flex; align-items:center; gap:7px; font-size:11.5px; font-weight:600; color:var(--ink-muted); min-width:0;}
.topnav .nav-right span:last-child{white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}

/* ============ Pannelli richiudibili (chat e dashboards) ============ */
.panel-rail{display:none;}
.collapse-btn{color:var(--ink-muted);}
.topnav .dot{width:8px; height:8px; border-radius:50%; background:var(--ok); flex-shrink:0;}
.topnav .dot.demo{background:var(--warn);} .topnav .dot.err{background:var(--crit);}
.page[hidden]{display:none !important;}

.layout{display:flex; height:calc(100dvh - var(--nav-h)); overflow:hidden;}

/* ============ Sidebar ============ */
.sidebar{width:272px; flex-shrink:0; background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; gap:10px; padding:14px 12px 12px; z-index:30; transition:width .18s ease;}
.side-top{display:flex; align-items:center; gap:6px;}
.side-top .new-chat{flex:1;}
@media (min-width: 861px){
  .sidebar.collapsed{width:56px; padding:14px 8px;}
  .sidebar.collapsed > :not(.panel-rail){display:none;}
  .sidebar.collapsed .panel-rail{display:flex; flex-direction:column; align-items:center; gap:8px;}
  .sidebar.collapsed .rail-new{background:var(--brand); color:#fff;}
  .sidebar.collapsed .rail-new:hover{background:var(--brand-soft); color:#fff;}
}
.side-brand{display:flex; align-items:center; gap:10px; padding:2px 6px 10px; border-bottom:1px solid var(--line);}
.side-brand .pictogram{height:36px; width:auto;}
.side-brand .wordmark{height:26px; width:auto;}
.new-chat{display:flex; align-items:center; gap:8px; justify-content:center; background:var(--brand); color:#fff;
  font-weight:700; font-size:13px; border-radius:11px; padding:10px 12px; transition:background .15s;}
.new-chat:hover{background:var(--brand-soft);}
.chat-list{flex:1; overflow-y:auto; display:flex; flex-direction:column; gap:2px; padding:4px 0;}
.list-label{font-size:10.5px; font-weight:800; text-transform:uppercase; letter-spacing:.05em; color:var(--ink-muted); padding:10px 8px 4px;}
.chat-item{display:flex; align-items:center; gap:6px; border-radius:10px; padding:8px 6px 8px 10px; position:relative;}
.chat-item:hover{background:var(--bg);}
.chat-item.active{background:var(--brand-wash);}
.chat-item .title{flex:1; min-width:0; text-align:left; font-weight:600; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.chat-item .pin-ico{color:var(--gold); flex-shrink:0; display:flex;}
.chat-item .more{opacity:0; width:24px; height:24px; border-radius:7px; display:flex; align-items:center; justify-content:center; color:var(--ink-muted); flex-shrink:0;}
.chat-item:hover .more,.chat-item.menu-open .more{opacity:1;}
.chat-item .more:hover{background:var(--line); color:var(--ink);}
.item-menu{position:absolute; right:4px; top:34px; background:var(--surface); border:1px solid var(--border);
  border-radius:12px; box-shadow:var(--shadow); padding:5px; z-index:50; min-width:150px; display:flex; flex-direction:column;}
.item-menu button{display:flex; align-items:center; gap:8px; padding:7px 10px; border-radius:8px; font-weight:600; font-size:12.5px; text-align:left;}
.item-menu button:hover{background:var(--bg);}
.item-menu button.danger{color:var(--crit);}
.item-menu button.danger:hover{background:var(--crit-wash);}
.side-foot{display:flex; align-items:center; gap:7px; font-size:11px; font-weight:600; color:var(--ink-muted); padding:8px 8px 2px; border-top:1px solid var(--line);}
.side-foot .dot{width:8px; height:8px; border-radius:50%; background:var(--ok); flex-shrink:0;}
.side-foot .dot.demo{background:var(--warn);}
.side-foot .dot.err{background:var(--crit);}

/* ============ Main ============ */
.main{flex:1; min-width:0; display:flex; flex-direction:column;}
.main-head{display:flex; align-items:baseline; gap:10px; padding:14px 22px 12px; border-bottom:1px solid var(--line); background:var(--bg);}
.main-head h1{margin:0; font-size:15.5px; font-weight:800; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.head-sub{font-size:11.5px; color:var(--ink-muted); font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.icon-btn{width:32px; height:32px; border-radius:9px; display:flex; align-items:center; justify-content:center; color:var(--ink-muted); flex-shrink:0;}
.icon-btn:hover{background:var(--line); color:var(--ink);}
.menu-btn{display:none; align-self:center;}

.messages{flex:1; overflow-y:auto; padding:22px 22px 10px; scroll-behavior:smooth;}
.messages-inner,.msg{max-width:860px; margin:0 auto;}

/* ---- empty state */
.empty-state{max-width:620px; margin:9vh auto 0; text-align:center; display:flex; flex-direction:column; align-items:center; gap:10px;}
.empty-logo{height:64px; opacity:.92;}
.empty-state h2{margin:8px 0 0; font-size:22px; font-weight:800;}
.empty-state p{margin:0; color:var(--ink-muted); font-size:13.5px; line-height:1.6;}
.suggestions{display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin-top:14px;}
.sugg{border:1px solid var(--border); background:var(--surface); border-radius:999px; padding:8px 14px; font-weight:600;
  font-size:12.5px; color:var(--ink); box-shadow:var(--shadow-sm); transition:border-color .15s, background .15s;}
.sugg:hover{border-color:var(--brand-soft); background:var(--brand-wash);}

/* ---- messaggi */
.msg{display:flex; gap:12px; margin-bottom:22px;}
.msg .avatar{width:30px; height:30px; border-radius:9px; flex-shrink:0; display:flex; align-items:center; justify-content:center; margin-top:2px;}
.msg.user .avatar{background:var(--brand); color:#fff; font-weight:800; font-size:12px;}
.msg.assistant .avatar{background:var(--surface); border:1px solid var(--border);}
.msg.assistant .avatar img{width:20px; height:20px;}
.msg .body{flex:1; min-width:0; position:relative;}
.msg.user .body{background:var(--brand-wash); border:1px solid #DFE6C8; border-radius:var(--radius); padding:10px 14px; white-space:pre-wrap; font-weight:500;}
.msg .meta-row{display:flex; align-items:center; gap:8px; margin-top:8px; flex-wrap:wrap;}
.copy-btn{display:inline-flex; align-items:center; gap:5px; font-size:11px; font-weight:700; color:var(--ink-muted);
  border:1px solid var(--border); background:var(--surface); border-radius:999px; padding:4px 10px; transition:all .15s;}
.copy-btn:hover{color:var(--ink); border-color:var(--ink-muted);}
.copy-btn.ok{color:var(--ok); border-color:var(--brand-tint); background:var(--brand-wash);}
.power-tag{font-size:10px; font-weight:700; border-radius:6px; padding:2px 7px; background:var(--tech-wash); color:var(--tech); letter-spacing:.02em;}

/* ---- contenuto markdown */
.prose{font-size:14px; line-height:1.62; overflow-wrap:break-word;}
.prose>:first-child{margin-top:0;} .prose>:last-child{margin-bottom:0;}
.prose h1,.prose h2,.prose h3{font-weight:800; margin:18px 0 8px; line-height:1.3;}
.prose h1{font-size:18px;} .prose h2{font-size:16px;} .prose h3{font-size:14.5px;}
.prose p{margin:8px 0;}
.prose ul,.prose ol{margin:8px 0; padding-left:22px;}
.prose li{margin:3px 0;}
.prose a{color:var(--tech); font-weight:600;}
.prose code{background:var(--line); border-radius:5px; padding:1px 5px; font-size:12.5px; font-family:ui-monospace,'SF Mono',Menlo,monospace;}
.prose pre{background:#2E2619; color:#F3EFE6; border-radius:12px; padding:13px 15px; overflow-x:auto; font-size:12.5px; line-height:1.55; position:relative;}
.prose pre code{background:none; padding:0; color:inherit; font-size:inherit;}
.prose table{border-collapse:collapse; width:100%; margin:12px 0; font-size:13px; background:var(--surface);
  border:1px solid var(--border); border-radius:12px; overflow:hidden; box-shadow:var(--shadow-sm); display:block; max-width:max-content; overflow-x:auto;}
.prose th{background:var(--brand-wash); color:var(--brand); font-weight:800; text-align:left; font-size:11.5px; text-transform:uppercase; letter-spacing:.03em;}
.prose th,.prose td{padding:8px 13px; border-bottom:1px solid var(--line);}
.prose tr:last-child td{border-bottom:0;}
.prose blockquote{border-left:3px solid var(--brand-tint); margin:10px 0; padding:2px 14px; color:var(--ink-muted);}
.chart-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:14px 16px;
  margin:12px 0; box-shadow:var(--shadow-sm);}
.chart-card h4{margin:0 0 10px; font-size:13.5px; font-weight:800;}
.chart-card .chart-box{position:relative; height:300px;}

/* ---- attività strumento (query LEO) */
.tool-chip{display:flex; flex-direction:column; gap:4px; background:var(--tech-wash); border:1px solid #D3E0E8;
  border-radius:12px; padding:9px 13px; margin:8px 0; font-size:12.5px;}
.tool-chip .head{display:flex; align-items:center; gap:8px; font-weight:700; color:var(--tech);}
.tool-chip .spinner{width:12px; height:12px; border:2px solid var(--tech-tint); border-top-color:var(--tech);
  border-radius:50%; animation:spin .8s linear infinite; flex-shrink:0;}
@keyframes spin{to{transform:rotate(360deg);}}
.tool-chip .badge{font-size:10px; font-weight:700; border-radius:6px; padding:1px 6px; background:var(--surface); color:var(--tech);}
.tool-chip details{margin-top:2px;}
.tool-chip summary{cursor:pointer; font-size:11px; font-weight:700; color:var(--tech-soft);}
.tool-chip pre{margin:6px 0 0; background:var(--surface); border:1px solid var(--line); border-radius:8px;
  padding:8px 10px; font-size:11.5px; overflow-x:auto; font-family:ui-monospace,'SF Mono',Menlo,monospace; color:var(--ink);}
.tool-chip.error{background:var(--crit-wash); border-color:#E8C9C1;}
.tool-chip.error .head{color:var(--crit);}
.tool-chip.error .badge{color:var(--crit);}
.tool-chip .note{font-size:11.5px; font-weight:500; color:var(--ink-muted);}
.tool-chip.schema{background:var(--brand-wash); border-color:#DFE6C8;}
.tool-chip.schema .head{color:var(--brand);}
.tool-chip.schema .badge{color:var(--brand);}
.tool-chip.schema .spinner{border-color:var(--brand-tint); border-top-color:var(--brand);}

/* ---- area attività (ragionamento + strumenti) */
.activity{display:flex; flex-direction:column; gap:6px;}
.activity:empty{display:none;}
.activity + .prose{margin-top:10px;}
.activity .tool-chip{margin:0;}
.reasoning{border-left:2px solid var(--line); padding:2px 0 2px 12px;}
.reasoning summary{cursor:pointer; list-style:none; display:inline-flex; align-items:center; gap:7px;
  font-size:12px; font-weight:700; color:var(--ink-muted);}
.reasoning summary::-webkit-details-marker{display:none;}
.reasoning summary:hover{color:var(--ink);}
.reasoning .r-ico{width:7px; height:7px; border-right:1.6px solid currentColor; border-bottom:1.6px solid currentColor;
  transform:rotate(-45deg); transition:transform .15s; margin-right:1px;}
.reasoning[open] .r-ico{transform:rotate(45deg);}
.reasoning.live .r-label{animation:blink 1.4s infinite;}
.reasoning .r-body{margin-top:6px; font-size:12.5px; line-height:1.55; color:var(--ink-muted); white-space:pre-wrap;
  max-height:260px; overflow-y:auto;}
.prose.is-error{color:var(--crit); font-weight:600;}

.typing{display:inline-flex; gap:4px; padding:6px 2px;}
.typing i{width:6px; height:6px; border-radius:50%; background:var(--ink-muted); animation:blink 1.2s infinite;}
.typing i:nth-child(2){animation-delay:.2s;} .typing i:nth-child(3){animation-delay:.4s;}
@keyframes blink{0%,60%,100%{opacity:.25;} 30%{opacity:1;}}

.error-note{background:var(--crit-wash); border:1px solid #E8C9C1; color:var(--crit); border-radius:12px;
  padding:10px 14px; font-weight:600; font-size:13px; margin:8px 0;}

/* ============ Composer ============ */
.composer-wrap{padding:6px 22px 14px; background:linear-gradient(transparent, var(--bg) 40%);}
.attach-chips{max-width:860px; margin:0 auto 6px; display:flex; flex-wrap:wrap; gap:6px;}
.attach-chip{display:inline-flex; align-items:center; gap:7px; background:var(--gold-wash); color:var(--gold);
  border:1px solid #EFD9BC; border-radius:999px; padding:4px 7px 4px 12px; font-size:12px; font-weight:700;}
.attach-chip .x{width:17px; height:17px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:12px;}
.attach-chip .x:hover{background:#EFD9BC;}
.attach-chip.loading{opacity:.6;}
.composer{max-width:860px; margin:0 auto; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  box-shadow:var(--shadow); display:flex; align-items:flex-end; gap:6px; padding:9px 10px;}
.composer:focus-within{border-color:var(--brand-soft);}
.attach-btn{border:1px solid var(--border); border-radius:50%; width:34px; height:34px; flex-shrink:0;}
.composer textarea{flex:1; border:0; resize:none; background:none; outline:none; font-size:14px; line-height:1.5;
  padding:7px 4px; max-height:200px; min-height:34px;}
.composer-right{display:flex; align-items:center; gap:8px; flex-shrink:0;}
.power{position:relative;}
.power-btn{display:flex; align-items:center; gap:6px; font-size:12px; font-weight:700; color:var(--ink-muted);
  border:1px solid var(--border); border-radius:999px; padding:7px 12px;}
.power-btn:hover{color:var(--ink); border-color:var(--ink-muted);}
.power-menu[hidden]{display:none;}
.power-menu{position:absolute; bottom:42px; right:0; background:var(--surface); border:1px solid var(--border);
  border-radius:14px; box-shadow:var(--shadow); padding:6px; width:265px; display:flex; flex-direction:column; gap:2px; z-index:40;}
.power-menu button{display:flex; flex-direction:column; align-items:flex-start; gap:1px; padding:9px 11px; border-radius:10px; text-align:left;}
.power-menu button:hover{background:var(--bg);}
.power-menu button.active{background:var(--brand-wash);}
.power-menu b{font-size:13px; font-weight:800;}
.power-menu span{font-size:11px; color:var(--ink-muted); font-weight:500;}
.send-btn{width:34px; height:34px; border-radius:50%; background:var(--brand); color:#fff; display:flex;
  align-items:center; justify-content:center; transition:background .15s, opacity .15s; flex-shrink:0;}
.send-btn:hover{background:var(--brand-soft);}
.send-btn:disabled{opacity:.35; cursor:default;}
.send-btn.stop{background:var(--crit);}
.composer-foot{max-width:860px; margin:8px auto 0; text-align:center; font-size:11px; color:var(--ink-muted); font-weight:500;}

/* ============ Mobile ============ */
.scrim{display:none;}
@media (max-width: 860px){
  .topnav{gap:10px; padding:0 12px;}
  .topnav .brand .wordmark{display:none;}
  .topnav .tab span{display:none;}
  .topnav .nav-right span:last-child{display:none;}
  .side-top .collapse-btn{display:none;}
  .sidebar{position:fixed; top:var(--nav-h); bottom:0; left:0; transform:translateX(-100%); transition:transform .2s ease; box-shadow:var(--shadow);}
  .sidebar.open{transform:translateX(0);}
  .scrim{display:none; position:fixed; inset:0; background:rgba(54,42,31,.35); z-index:25;}
  .scrim.show{display:block;}
  .menu-btn{display:flex;}
  .messages{padding:16px 14px 8px;}
  .composer-wrap{padding:6px 10px 10px;}
  .head-sub{display:none;}
}
