:root {
  --bg: #020817;
  --card: rgba(15, 30, 70, .35);
  --line: rgba(120, 160, 255, .18);
  --text: #e8eeff;
  --muted: #7d8db5;
  --blue: #2f6bff;
  --cyan: #7fb2ff;
  --ok: #3ddc97;
  --warn: #ffb547;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }

.halo {
  position: fixed; left: 50%; bottom: -95vh; width: 160vh; height: 160vh; transform: translateX(-50%);
  border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 60px 10px rgba(47,107,255,.55), inset 0 0 80px 20px rgba(47,107,255,.35);
  border: 2px solid rgba(160,195,255,.75);
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 22px 32px; position: relative; z-index: 2; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; letter-spacing: .3em; color: var(--text); }
.brand .ai { color: var(--cyan); letter-spacing: .1em; }
.pill {
  display: flex; gap: 8px; align-items: center; padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(10,20,45,.6); font-size: 14px;
}
.clock .sep { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.err { background: #ff5d6c; }

.layout {
  display: grid; grid-template-columns: 280px 1fr 300px; gap: 28px;
  padding: 0 32px 32px; height: calc(100% - 86px); position: relative; z-index: 2;
}
.panel { display: flex; flex-direction: column; gap: 18px; overflow: auto; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px 20px;
  backdrop-filter: blur(14px);
}
.card h2 { margin: 0 0 12px; font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.stats { display: flex; gap: 22px; }
.stats > div { display: flex; flex-direction: column; }
.big { font-size: 30px; font-weight: 600; }
.big.accent { color: var(--cyan); }
.label, .small { font-size: 12px; color: var(--muted); }
.small { margin: 8px 0 0; }

.agents, .apps { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.agents li, .apps li { display: flex; align-items: center; justify-content: space-between; font-size: 14px; padding: 7px 10px; border-radius: 12px; background: rgba(255,255,255,.03); }
.agents li .st { font-size: 12px; color: var(--muted); }
.agents li.busy { background: rgba(47,107,255,.18); }
.agents li.busy .st { color: var(--cyan); }
.agents li.busy .st::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--cyan); animation: pulse 1s infinite; }
.apps .badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.apps .badge.attiva { color: var(--ok); border-color: rgba(61,220,151,.4); }
@keyframes pulse { 50% { opacity: .2; } }

.bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,.07); margin-top: 14px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .6s; }
.bar > div.warn { background: var(--warn); }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 46px; margin-top: 14px; }
.spark i { flex: 1; background: rgba(127,178,255,.35); border-radius: 4px 4px 0 0; min-height: 2px; }

.stage { display: flex; align-items: center; justify-content: center; }
.voice-card {
  position: relative; width: min(560px, 100%); height: min(680px, 100%);
  border-radius: 40px; border: 1px solid var(--line); overflow: hidden;
  background: linear-gradient(180deg, rgba(40,80,170,.55) 0%, rgba(4,12,35,.9) 45%, rgba(10,50,200,.85) 100%);
  backdrop-filter: blur(18px); box-shadow: 0 30px 80px rgba(0,0,0,.55); display: flex; flex-direction: column; padding: 34px 36px 26px;
}
.voice-card::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 40%; pointer-events: none;
  background-image: radial-gradient(rgba(140,180,255,.25) 1px, transparent 1px); background-size: 14px 14px;
  mask-image: linear-gradient(transparent, #000);
}
.transcript { font-size: 26px; line-height: 1.3; margin: 18px 40px 0 0; color: #b9c6e6; min-height: 70px; }
.transcript .muted { color: var(--muted); }
.transcript b { color: #fff; font-weight: 500; }
.reply { font-size: 15px; line-height: 1.5; color: var(--text); margin-top: 14px; overflow: auto; flex: 1; white-space: pre-wrap; padding-right: 6px; }
.reply .tag { color: var(--cyan); font-weight: 600; margin-right: 6px; }
.reply.error { color: #ffb3bb; }
#wave { width: 100%; height: 140px; flex: none; }
.controls { display: flex; justify-content: center; align-items: center; gap: 18px; position: relative; z-index: 1; }
.mic {
  width: 92px; height: 92px; border-radius: 50%; border: none; background: #fff; color: #0b1430; cursor: pointer;
  box-shadow: 0 10px 30px rgba(47,107,255,.6); transition: transform .15s, box-shadow .15s;
}
.mic.listening { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(127,178,255,.25), 0 0 50px rgba(127,178,255,.9); }
.mic.thinking { animation: pulse 1.2s infinite; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.08);
  color: var(--text); cursor: pointer; font-size: 15px;
}
.settings-btn { position: absolute; right: 28px; top: 28px; }
.typebox { display: flex; gap: 8px; margin-top: 16px; position: relative; z-index: 1; }
.typebox input, .settings input, .settings select {
  flex: 1; padding: 11px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(2,8,23,.6); color: var(--text); font: inherit;
}
button { font: inherit; }
.typebox button, .settings button {
  padding: 10px 16px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--text); cursor: pointer;
}
.settings button.primary { background: var(--blue); border-color: var(--blue); }

dialog { border: 1px solid var(--line); border-radius: 22px; background: #071229; color: var(--text); padding: 0; width: min(460px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.settings { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.settings h2 { margin: 0; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.settings .row { flex-direction: row; align-items: center; display: flex; gap: 8px; }
.settings .end { justify-content: flex-end; }

@media (max-width: 1100px) {
  html, body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .stage { order: -1; }
  .voice-card { height: 600px; }
}

.voice-pick {
  position: absolute; left: 28px; top: 28px; display: flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.08); font-size: 13px; z-index: 2;
}
.voice-pick select { background: transparent; border: none; color: var(--text); font: inherit; max-width: 210px; cursor: pointer; outline: none; }
.voice-pick select option { background: #071229; }
.transcript { margin-top: 44px; }

/* ---------- accesso e progetti ---------- */
.gate {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(ellipse at 30% 20%, rgba(20,40,180,.45), transparent 55%),
              linear-gradient(115deg, #000 0 30%, #08155e 30% 42%, #000 42% 62%, #071250 62% 72%, #000 72%), #000;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(420px, 100%); padding: 40px 34px 30px; border-radius: 40px; text-align: center;
  background: linear-gradient(180deg, rgba(30,90,255,.55), rgba(4,10,40,.92) 35%, rgba(4,10,40,.92) 75%, rgba(20,60,230,.45));
  border: 1px solid rgba(120,170,255,.35); box-shadow: 0 0 60px rgba(30,90,255,.35); backdrop-filter: blur(20px);
}
.gate-card h1 { margin: 6px 0 2px; font-size: 34px; font-weight: 700; }
.gate-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.gate-logo img { border-radius: 14px; }
.field {
  display: flex; flex-direction: column; text-align: left; gap: 2px; margin: 12px 0; padding: 9px 20px; position: relative;
  border-radius: 999px; background: rgba(20,24,45,.85); border: 1px solid rgba(255,255,255,.18); box-shadow: inset 0 1px 6px rgba(0,0,0,.6);
}
.field span { font-size: 12px; color: var(--muted); }
.field input { background: none; border: none; outline: none; color: var(--text); font: inherit; font-size: 15px; padding: 0; }
.field.with-btn { padding-right: 64px; }
.go {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: none;
  background: radial-gradient(circle at 35% 30%, #6fc3ff, #1b6dff 60%, #0a3bb8); color: #000; font-size: 22px; cursor: pointer;
  box-shadow: 0 0 22px rgba(60,150,255,.8);
}
.gate-msg { min-height: 20px; font-size: 13px; color: #ffb3bb; margin: 6px 0; }
.gate-msg.ok { color: var(--ok); }
.gate-links { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.link { background: none; border: none; color: var(--cyan); cursor: pointer; font-size: 13px; padding: 4px; }
.projects-card { text-align: left; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.project-list { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow: auto; }
.project-list button.open {
  width: 100%; text-align: left; padding: 14px 18px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(255,255,255,.05); color: var(--text); cursor: pointer; font-size: 15px;
}
.project-list button.open:hover { background: rgba(47,107,255,.25); }
.project-list small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.new-project { display: flex; flex-direction: column; gap: 8px; }
.new-project input, .new-project textarea {
  padding: 12px 16px; border-radius: 16px; border: 1px solid var(--line); background: rgba(2,8,23,.7); color: var(--text); font: inherit; resize: vertical;
}
.new-project .primary { padding: 12px; border-radius: 16px; border: none; background: var(--blue); color: #fff; cursor: pointer; font: inherit; }
.project-pill { cursor: pointer; color: var(--text); }
.project-pill[hidden] { display: none; }
.field[hidden] { display: none; }
.invite-note { margin: 4px 0 0; font-size: 12px; }
.invite-note[hidden], .link[hidden] { display: none; }

/* ---------- demo pubblica ---------- */
.demo-bar { position: relative; z-index: 3; text-align: center; font-size: 12px; padding: 7px 12px; color: #cfe0ff; background: linear-gradient(90deg, rgba(47,107,255,.15), rgba(47,107,255,.4), rgba(47,107,255,.15)); }
.demo-bar[hidden], .chips[hidden] { display: none; }
.demo-bar a { color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; position: relative; z-index: 1; }
.chips button { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.07); color: var(--text); cursor: pointer; font-size: 13px; }
.chips button:hover { background: rgba(47,107,255,.3); }
body.demo .layout { height: calc(100% - 118px); }
.apps .badge.demo { color: #ffd38a; border-color: rgba(255,181,71,.4); }

/* ---------- risposta: grafici ---------- */
.chart-card {
  margin: 16px 0 6px; padding: 18px 18px 10px; border-radius: 22px; position: relative; white-space: normal;
  background: linear-gradient(160deg, rgba(40,30,90,.65), rgba(8,8,30,.85) 60%);
  border: 1px solid rgba(167,139,250,.45);
  box-shadow: 0 0 0 1px rgba(167,139,250,.1), 0 0 30px rgba(139,92,246,.35), inset 0 1px 0 rgba(255,255,255,.08);
}
.chart-card::after { content: ""; position: absolute; left: 15%; right: 15%; bottom: -14px; height: 14px; border-radius: 50%; background: radial-gradient(rgba(139,92,246,.6), transparent 70%); filter: blur(6px); }
.chart-card figcaption { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.chart-title { font-size: 15px; color: #e9e6ff; }
.chart-value { font-size: 26px; font-weight: 500; margin-top: 6px; color: #fff; }
.chart-delta { font-size: 12px; padding: 5px 10px; border-radius: 10px; background: rgba(139,92,246,.18); border: 1px solid rgba(167,139,250,.35); color: #c4b5fd; white-space: nowrap; }
.chart-delta.down { color: #fda4af; border-color: rgba(253,164,175,.4); background: rgba(244,63,94,.12); }
.chart-card svg { width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.chart-card .grid { stroke: rgba(255,255,255,.07); }
.chart-card .ax { fill: #9aa3c7; font-size: 11px; }
.chart-card .dot { fill: var(--c); opacity: .8; }
.chart-card .dot-last { fill: #fff; stroke: var(--c); stroke-width: 3; filter: drop-shadow(0 0 6px var(--c)); }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: #9aa3c7; margin-top: 4px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.thinking-dots i { animation: pulse 1s infinite; font-style: normal; }
.thinking-dots i:nth-child(2) { animation-delay: .2s; } .thinking-dots i:nth-child(3) { animation-delay: .4s; }
.doc-chip { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.1); vertical-align: middle; }

/* ---------- caricamento documento ---------- */
.attach { width: 44px; flex: none; display: grid; place-items: center; padding: 0 !important; }
.upload-card {
  position: absolute; left: 22px; right: 22px; bottom: 90px; z-index: 5; padding: 22px; border-radius: 28px;
  background: linear-gradient(180deg, rgba(10,20,45,.96), rgba(18,40,110,.96)); border: 1px solid rgba(140,170,255,.25);
  box-shadow: 0 20px 60px rgba(0,0,0,.6), 0 30px 60px -20px rgba(47,107,255,.6);
}
.upload-card[hidden] { display: none; }
.upload-close { position: absolute; right: 16px; top: 16px; }
.upload-top { display: flex; gap: 22px; align-items: center; margin-bottom: 18px; }
.file-icon { position: relative; width: 92px; height: 100px; flex: none; }
.file-sheet {
  position: absolute; right: 0; top: 0; width: 70px; height: 92px; border-radius: 10px 22px 10px 10px;
  background: linear-gradient(160deg, #6fb0ff, #2a5fd6 70%), repeating-linear-gradient(0deg, transparent 0 11px, rgba(255,255,255,.15) 11px 12px);
  background-blend-mode: overlay; box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
}
.file-badge {
  position: absolute; left: 0; bottom: 14px; padding: 7px 10px; border-radius: 10px; font-weight: 800; font-size: 18px; letter-spacing: .04em;
  color: #1a2440; background: linear-gradient(180deg, #c6d2f0, #8e9cc6); border: 3px solid #2a3a66; box-shadow: 0 6px 14px rgba(0,0,0,.4);
}
.upload-name { font-size: 22px; font-weight: 600; word-break: break-all; }
.upload-size { color: var(--muted); margin-top: 4px; }
.upload-bar { padding: 14px 16px; border-radius: 18px; background: rgba(2,6,20,.85); border: 1px solid var(--line); }
.upload-row { display: flex; align-items: center; gap: 10px; color: #c9d3ee; }
.upload-pct { margin-left: auto; font-size: 30px; font-weight: 300; color: #fff; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.upload-track { height: 5px; border-radius: 5px; background: rgba(255,255,255,.12); margin-top: 10px; overflow: hidden; }
.upload-track > div { height: 100%; width: 0; border-radius: 5px; background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.8); transition: width .2s; }

.voice-card { transition: width .3s; }
.voice-card.answering #wave { height: 64px; }
.voice-card.answering .transcript { font-size: 20px; min-height: 0; }
.voice-card.has-charts { width: min(720px, 100%); }
.voice-card.answering .mic { width: 70px; height: 70px; }

/* =================== smartphone =================== */
.m-only { display: none; }
#orb { width: 230px; height: 230px; }

@media (max-width: 760px) {
  html, body { overflow: hidden; height: 100%; background: #000; }
  body { height: 100dvh; }
  .halo { display: none; }
  .m-only { display: revert; }
  .top { padding: 12px 16px; gap: 8px; }
  .top .brand { font-size: 13px; letter-spacing: .2em; }
  .top .brand svg { height: 14px; }
  .clock #date, .clock .sep, #conn-label, .project-pill { display: none !important; }
  .pill { padding: 7px 12px; font-size: 13px; }
  .demo-bar { font-size: 11px; padding: 6px 10px; }
  .layout { display: block; padding: 0; height: calc(100dvh - 56px); }
  body.demo .layout { height: calc(100dvh - 86px); }

  /* pannello stato: foglio dal basso */
  .panel { display: none; }
  body.sheet-open .panel {
    display: flex; position: fixed; left: 0; right: 0; z-index: 30; padding: 16px; gap: 12px; overflow: auto;
    background: rgba(4,8,22,.97); border-top: 1px solid var(--line); backdrop-filter: blur(20px);
  }
  body.sheet-open .panel.left { top: 56px; bottom: 50%; border-radius: 0 0 24px 24px; border-top: none; border-bottom: 1px solid var(--line); }
  body.sheet-open .panel.right { top: 50%; bottom: 0; border-radius: 24px 24px 0 0; }
  .m-stats-btn {
    position: fixed; right: 14px; top: 64px; z-index: 31; width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--line); background: rgba(20,30,60,.7); color: var(--cyan); font-size: 18px;
  }
  body.demo .m-stats-btn { top: 94px; }

  /* scheda principale = schermo intero, bagliore blu dal basso come nel video */
  .stage { height: 100%; }
  .voice-card {
    width: 100% !important; height: 100%; border: none; border-radius: 0; padding: 14px 16px calc(84px + env(safe-area-inset-bottom));
    background: radial-gradient(120% 45% at 50% 108%, rgba(30,90,255,.85), rgba(10,40,160,.35) 45%, transparent 75%), #000;
    box-shadow: none; backdrop-filter: none;
  }
  .voice-card::after { display: none; }
  .voice-pick { left: 14px; top: 10px; }
  .settings-btn { right: 60px; top: 10px; width: 36px; height: 36px; }
  #wave, .controls { display: none !important; }
  .m-new { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 2; padding: 7px 14px; border-radius: 999px;
    border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text); font-size: 13px; }

  .m-hero { position: absolute; inset: 60px 0 100px; display: flex !important; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; transition: opacity .4s; }
  .m-hello { color: var(--muted); margin: 6px 0 4px; font-size: 15px; transition: filter .4s, opacity .4s; }
  .m-title { margin: 0; font-size: 30px; line-height: 1.15; font-weight: 600; max-width: 280px; transition: filter .4s, opacity .4s; }
  #orb { transition: transform .5s, filter .5s; }

  .transcript, .reply, .chips { display: none; }
  .typebox {
    position: absolute; left: 14px; right: 14px; bottom: calc(18px + env(safe-area-inset-bottom)); margin: 0; gap: 4px; align-items: center;
    padding: 6px; border-radius: 999px; background: rgba(30,40,70,.75); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(16px);
  }
  .typebox input#typed { border: none; background: transparent; padding: 10px 6px; font-size: 16px; }
  .typebox .attach, .typebox .m-mic { width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: var(--text); display: grid; place-items: center; padding: 0; }
  .typebox .m-mic.listening { background: rgba(127,178,255,.25); box-shadow: 0 0 18px rgba(127,178,255,.8); }
  .typebox .send-btn { display: none; }
  .upload-card { left: 12px; right: 12px; bottom: 84px; padding: 16px; }
  .file-icon { transform: scale(.8); transform-origin: left center; width: 74px; }
  .upload-name { font-size: 17px; }
  .upload-pct { font-size: 24px; }

  /* stati */
  .voice-card.m-idle .chips:not([hidden]) { display: flex; position: absolute; left: 16px; right: 16px; bottom: 96px; justify-content: center; }
  .voice-card.m-idle .m-new { display: none; }
  .voice-card.m-thinking #orb { transform: scale(.62); filter: blur(1px); }
  .voice-card.m-thinking .m-hello, .voice-card.m-thinking .m-title { filter: blur(6px); opacity: .5; }
  .voice-card.m-thinking .m-new, .voice-card.m-found .m-new { display: none; }
  .voice-card.m-thinking .typebox, .voice-card.m-found .typebox { pointer-events: none; }
  .voice-card.m-answer .m-hero { opacity: 0; }
  .voice-card.m-answer .transcript {
    display: block; align-self: flex-end; max-width: 80%; margin: 44px 0 0 auto; padding: 10px 14px; border-radius: 18px 18px 4px 18px;
    background: rgba(255,255,255,.1); font-size: 15px; color: var(--text);
  }
  .voice-card.m-answer .reply { display: block; font-size: 15px; padding-bottom: 20px; }
  .chart-card { padding: 14px 12px 8px; }
  .chart-value { font-size: 22px; }
}
@media (max-width: 760px) {
  body.demo .voice-card.m-idle .m-hero { bottom: 250px; }
  body.demo .voice-card.m-idle #orb { width: 190px; height: 190px; }
  .voice-card.m-idle .chips:not([hidden]) { flex-direction: column; align-items: stretch; gap: 8px; }
  .voice-card.m-idle .chips button { font-size: 13px; padding: 10px 14px; background: rgba(255,255,255,.06); }
}
@media (max-width: 760px) and (max-height: 700px) {
  body.demo .voice-card.m-idle #orb { width: 140px; height: 140px; }
  .m-title { font-size: 24px; }
}
