:root {
  --bg: #0d0f15;          /* near-black bluastro */
  --panel: #13161f;       /* pannelli (chat / chrome anteprima) */
  --panel-2: #1a1e2a;     /* inset: input, bolle bot, chip */
  --inset: #0f121a;       /* campi di testo */
  --line: #262b39;        /* filo */
  --line-2: #343b4d;      /* filo hover / più marcato */
  --ink: #eef1f7;         /* testo */
  --ink-soft: #98a1b4;    /* secondario */
  --ink-faint: #677087;   /* terziario / mono */
  --violet: #8b5cf6;
  --blue: #5b8cff;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #5b8cff 100%);
  --accent: #7c8cff;      /* accento pieno per dettagli/link/focus */
  --accent-soft: rgba(124,140,255,.16);
  --ok: #34d399;  --ok-bg: rgba(52,211,153,.12);
  --warn: #f5b54a; --warn-bg: rgba(245,181,74,.13);
  --radius: 14px;
  --shadow: 0 18px 44px -26px rgba(0,0,0,.75);
  --mono: "Spline Sans Mono", ui-monospace, monospace;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --display: "Bricolage Grotesque", var(--sans);
}

* { box-sizing: border-box; touch-action: manipulation; }
html, body { height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(90% 60% at 100% -5%, rgba(139,92,246,.10), transparent 60%),
    radial-gradient(80% 55% at -5% 105%, rgba(91,140,255,.10), transparent 60%),
    var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(13,15,21,.72);
  backdrop-filter: saturate(150%) blur(10px);
  position: relative; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 30px; width: auto; display: block; }
.tag {
  font-family: var(--mono); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .28em; color: var(--ink-faint);
  padding-left: 12px; border-left: 1px solid var(--line);
}
.top-actions { display: flex; gap: 10px; align-items: center; }
.btn-ic { display: none; }
.mobile-tabs { display: none; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); position: relative; z-index: 9; flex-shrink: 0; }
.mtab { flex: 1; padding: 9px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-soft); font-family: var(--sans); font-weight: 600; font-size: 13px; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.mtab.active { background: var(--grad); color: #fff; border-color: transparent; }

/* ---- buttons / inputs ---- */
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 13px;
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  padding: 8px 15px; border-radius: 10px; cursor: pointer;
  transition: transform .1s ease, background .16s ease, color .16s ease, border-color .16s, box-shadow .2s, opacity .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); color: var(--ink); border-color: var(--line-2); background: var(--panel-2); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.accent {
  background: var(--grad); border: 0; color: #fff;
  box-shadow: 0 8px 22px -10px rgba(123,116,255,.7);
}
.btn.accent:hover:not(:disabled) { filter: brightness(1.07); box-shadow: 0 12px 28px -10px rgba(123,116,255,.85); color: #fff; }
.btn.ghost { border-color: var(--line); color: var(--ink-soft); background: transparent; }
.select {
  font-family: var(--sans); font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 7px 12px; max-width: 220px; cursor: pointer;
}
.select:hover { border-color: var(--line-2); }
.select:focus { outline: none; border-color: var(--accent); }

/* ---- layout ---- */
.grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 388px 1fr;
}
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.preview { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }

/* ---- chat ---- */
.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 92%; padding: 12px 15px; border-radius: 16px; font-size: 14px; line-height: 1.55; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg.bot { background: var(--panel-2); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.user { background: var(--grad); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; box-shadow: 0 10px 26px -14px rgba(123,116,255,.7); }
.msg.user .tiny, .msg.user .muted { color: rgba(255,255,255,.8); }
.msg.intro { background: transparent; border: 0; padding: 4px 2px; max-width: 100%; }
.msg.intro .lead { font-family: var(--display); font-weight: 600; font-size: 21px; line-height: 1.2; color: var(--ink); margin-bottom: 8px; letter-spacing: -.01em; }
.msg .muted { color: var(--ink-soft); font-size: 13px; }
.msg.err { border-color: rgba(248,113,113,.5); background: rgba(248,113,113,.1); }
.msg.ok-note { border-color: rgba(52,211,153,.4); background: var(--ok-bg); }
.msg ul { margin: 6px 0 0; padding-left: 18px; }
.msg li { margin: 2px 0; }
.msg .tiny { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); letter-spacing: .03em; }
.msg.thinking { color: var(--ink-soft); font-style: italic; background: transparent; border: 0; }

/* intake (domande di chiarimento) */
.intake .q-block { margin: 12px 0; }
.intake .q { font-weight: 700; font-size: 15px; margin: 0 0 6px; color: var(--ink); }
.intake .opts { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 6px; }
.intake .opt {
  font-family: var(--sans); font-weight: 500; font-size: 12.5px; cursor: pointer;
  border: 1px solid var(--line); background: var(--inset); color: var(--ink);
  border-radius: 999px; padding: 6px 13px; transition: border-color .15s, background .15s;
}
.intake .opt:hover { border-color: var(--accent); background: var(--panel-2); }
.intake .opt.sel { background: var(--grad); color: #fff; border-color: transparent; }
.intake .q-text {
  width: 100%; font-family: var(--sans); font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--inset);
}
.intake .q-text::placeholder { color: var(--ink-faint); }
.intake .q-text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.intake .build-btn { margin-top: 8px; }
.intake button:disabled, .intake input:disabled { opacity: .5; cursor: default; }
.dotting::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "··"; } 75% { content: "···"; } }

.composer {
  margin: 12px; padding: 6px 8px 6px 10px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--inset);
  display: flex; align-items: center; gap: 8px;            /* chiuso: una riga */
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--line-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; background: transparent; color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; padding: 7px 4px;
  min-height: 24px; max-height: 50vh; overflow-y: auto;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--ink-faint); }
.composer-bar { display: flex; align-items: center; gap: 8px; flex: none; }
.composer.expanded { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; }
.composer.expanded textarea { flex: none; width: 100%; padding: 6px 6px 0; }
.composer.expanded .composer-bar { justify-content: flex-end; }
.composer .btn { height: 36px; min-width: 76px; border-radius: 10px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; }
.mic-btn {
  flex: none; width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}
.mic-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--line-2); }
.mic-btn:disabled { opacity: .4; cursor: not-allowed; }
.mic-btn.rec { color: #fff; background: var(--grad); border-color: transparent; animation: micpulse 1.3s ease-in-out infinite; }
@keyframes micpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(123,116,255,.5); } 50% { box-shadow: 0 0 0 7px rgba(123,116,255,0); } }

/* ---- allegati (fase testo) ---- */
.composer { flex-wrap: wrap; }
.composer.dragging { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.attach-btn svg { display: block; }
.attach-list { order: -1; width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 100%;
  padding: 5px 8px 5px 9px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2); color: var(--ink-soft); font-size: 12px; line-height: 1.2;
}
.attach-chip .ac-ic { flex: none; display: inline-flex; color: var(--ink-faint); }
.attach-chip .ac-name { color: var(--ink); font-weight: 500; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ac-meta { flex: none; color: var(--ink-faint); }
.attach-chip .ac-x {
  flex: none; border: 0; background: transparent; cursor: pointer; color: var(--ink-faint);
  font-size: 12px; line-height: 1; padding: 2px; border-radius: 5px;
}
.attach-chip .ac-x:hover { color: var(--ink); background: var(--inset); }
.attach-chip.is-error { border-color: rgba(220,80,80,.5); background: rgba(220,80,80,.08); }
.attach-chip.is-error .ac-meta { color: #d05050; }
.attach-chip.is-empty .ac-meta { color: #b98a2e; }
.attach-chip.is-loading { opacity: .85; }
.ac-spin {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--accent);
  display: inline-block; animation: acspin .7s linear infinite;
}
@keyframes acspin { to { transform: rotate(360deg); } }
.attach-note { width: 100%; font-size: 12px; color: var(--ink-faint); padding: 2px 2px 0; }
.attach-chip.is-image { padding-left: 5px; }
.ac-thumb { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; display: block; }
.msg-files { margin: 6px 0 0; font-size: 12px; opacity: .8; line-height: 1.45; }

/* ---- import da URL ---- */
.link-btn svg { display: block; }
.import-card { width: min(560px, 94vw); max-height: 86vh; overflow-y: auto; }
.imp-url { display: flex; gap: 8px; }
.imp-url .text-input { flex: 1; }
.imp-status { margin: 8px 0 0; color: var(--ink-faint); }
.imp-text { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); cursor: pointer; }
.imp-preview { margin: 6px 0 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--inset); color: var(--ink-soft); max-height: 110px; overflow-y: auto; white-space: pre-wrap; }
.imp-imgs-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; font-size: 13px; color: var(--ink-soft); }
.imp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.imp-tile { position: relative; padding: 0; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--panel-2); aspect-ratio: 1 / 1; }
.imp-tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .55; transition: opacity .15s; }
.imp-tile.selected { border-color: var(--accent); }
.imp-tile.selected img { opacity: 1; }
.imp-tile.broken { opacity: .35; cursor: not-allowed; }
.imp-check { position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--grad); color: #fff; font-size: 12px; display: none; align-items: center; justify-content: center; }
.imp-tile.selected .imp-check { display: flex; }
.linklike { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.imp-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* menu "allega" */
.attach-menu { position: fixed; z-index: 200; min-width: 210px; padding: 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.34); display: flex; flex-direction: column; gap: 2px; }
.attach-menu button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; border-radius: 8px; cursor: pointer; text-align: left; width: 100%; }
.attach-menu button:hover { background: var(--inset); }
.attach-menu .am-ic { width: 18px; text-align: center; flex: none; }

/* ---- preview toolbar ---- */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.status { display: flex; align-items: center; gap: 10px; }
.pill {
  font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft);
}
.pill.preview { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.approved { background: var(--panel-2); color: var(--ink); border-color: var(--line-2); }
.pill.published { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.ver { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.routes { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.routes-scroll { display: flex; align-items: center; gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.routes-scroll::-webkit-scrollbar { height: 6px; }
.routes-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 999px; }
.chip {
  flex: 0 0 auto;
  font-family: var(--mono); font-size: 11px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; background: var(--panel-2);
  transition: color .15s, border-color .15s;
}
.chip:hover { color: var(--ink); border-color: var(--accent); }
.chip.active { color: var(--ink); border-color: var(--line-2); background: var(--panel); }
.routes-more { position: relative; flex: 0 0 auto; }
.more-btn { display: inline-flex; align-items: center; gap: 4px; }
.more-btn .caret { opacity: .7; }
.routes-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 170px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px;
  box-shadow: 0 16px 40px -18px rgba(0,0,0,.7); display: flex; flex-direction: column; gap: 2px;
  max-height: 320px; overflow-y: auto;
}
.routes-menu[hidden] { display: none !important; }
.routes-menu-item {
  text-align: left; font-family: var(--mono); font-size: 12px; color: var(--ink-soft);
  padding: 7px 10px; border-radius: 7px; border: 0; background: transparent; cursor: pointer;
}
.routes-menu-item:hover, .routes-menu-item.active { background: var(--panel-2); color: var(--ink); }
.actions { display: flex; gap: 8px; }

/* ---- menu progetti ---- */
.proj-wrap { position: relative; }
.proj-btn { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; }
.proj-btn .caret { opacity: .7; }
.proj-btn-label { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; min-width: 240px; max-width: 320px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px;
  box-shadow: 0 16px 40px -18px rgba(0,0,0,.7); display: flex; flex-direction: column; gap: 2px;
  max-height: 360px; overflow-y: auto;
}
.proj-menu[hidden] { display: none !important; }
.proj-row { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.proj-row:hover { background: var(--panel-2); }
.proj-open {
  flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 1px;
  padding: 7px 9px; border: 0; background: transparent; cursor: pointer; border-radius: 7px;
}
.proj-name { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-row.active .proj-name { color: var(--accent); }
.proj-meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); letter-spacing: .02em; }
.proj-del {
  width: 26px; min-width: 26px; height: 26px; border: 0; background: transparent; color: var(--ink-faint);
  border-radius: 7px; cursor: pointer; font-size: 18px; line-height: 1;
}
.proj-del:hover { background: rgba(248,113,113,.15); color: #fca5a5; }
.proj-empty { color: var(--ink-faint); font-size: 12px; padding: 8px 10px; margin: 0; }

.btn.danger { color: #fca5a5; border-color: rgba(248,113,113,.35); }
.btn.danger:hover:not(:disabled) { background: rgba(248,113,113,.15); color: #fecaca; border-color: rgba(248,113,113,.5); }

/* ---- frame ---- */
.frame-wrap { position: relative; flex: 1; min-height: 0; background: var(--bg); }
#frame { width: 100%; height: 100%; border: 0; background: #fff; }
.placeholder, .busy {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 24px;
}
/* l'attributo `hidden` deve vincere su display:flex qui sopra */
.placeholder[hidden], .busy[hidden], #frame[hidden], .editbar[hidden] { display: none !important; }
.placeholder {
  background:
    radial-gradient(50% 45% at 50% 42%, rgba(124,140,255,.10), transparent 70%);
}
.busy { background: rgba(13,15,21,.84); backdrop-filter: blur(3px); }
.ph-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink-soft); }
.ph-logo { width: 72px; height: 72px; display: block; filter: drop-shadow(0 12px 30px rgba(124,140,255,.35)); animation: float 4s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.placeholder p { color: var(--ink-soft); margin: 10px 0 0; font-size: 14px; }
.muted { color: var(--ink-soft); }
.small { font-size: 12px; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy p { margin: 0; }
#busyText { font-family: var(--display); font-weight: 600; font-size: 18px; color: var(--ink); }

/* barra di avanzamento (build) */
.progress {
  width: min(320px, 70%); height: 8px; border-radius: 999px;
  background: var(--panel-2); overflow: hidden; margin: 2px 0; border: 1px solid var(--line);
}
.progress-fill {
  height: 100%; width: 2%; border-radius: 999px;
  background: var(--grad); transition: width .3s ease;
}

/* intake wizard */
.intake-prog { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 6px; }
.intake-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.intake-row .q-text { flex: 1; min-width: 160px; }
.intake-hint { font-size: 12px; color: var(--ink-faint); margin: 0 0 6px; }
.intake-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.intake-skipall { background: none; border: 0; color: var(--ink-faint); font-size: 12px; cursor: pointer; text-decoration: underline; padding: 2px 0; }
.intake-skipall:hover { color: var(--ink-soft); }

a { color: var(--accent); }

/* ---- modifica diretta ---- */
.swatches { display: inline-flex; gap: 6px; }
.swatches button {
  width: 22px; height: 22px; border-radius: 999px; border: 2px solid var(--panel-2);
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0;
}
.swatches button:hover { box-shadow: 0 0 0 1px var(--line-2); }
.swatches button.active { box-shadow: 0 0 0 2px var(--ink); }
.accent-color {
  width: 30px; height: 26px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: none; cursor: pointer;
}
#editBtn.active { background: var(--grad); color: #fff; border-color: transparent; }

/* pannello impostazioni (modale) */
.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,12,.6); backdrop-filter: blur(3px); padding: 24px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow); padding: 22px;
  max-height: calc(100vh - 48px); overflow-y: auto;
}
.modal-card.compact .set-row { margin-bottom: 10px; gap: 5px; }
.cg-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .cg-2 { grid-template-columns: 1fr; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-family: var(--display); font-weight: 700; font-size: 18px; margin: 0; color: var(--ink); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: transparent;
  color: var(--ink-soft); font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.set-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.set-row > label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.set-control { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.text-input {
  flex: 1; min-width: 160px; font-family: var(--sans); font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--inset);
}
.text-input::placeholder { color: var(--ink-faint); }
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.set-note { font-size: 12.5px; color: var(--ink-faint); margin: 4px 0 0; line-height: 1.5; }

/* barra contestuale (sull'elemento selezionato) */
.ctxbar {
  position: absolute; z-index: 40; display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  max-width: calc(100% - 16px);
  padding: 5px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line-2);
  box-shadow: 0 14px 34px -16px rgba(0,0,0,.7);
}
.ctxbar[hidden] { display: none !important; }
.ctxbar button {
  height: 30px; min-width: 30px; padding: 0 8px; border-radius: 8px; border: 0; cursor: pointer;
  background: transparent; color: var(--ink-soft); font-family: var(--sans); font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.ctxbar button:hover { background: var(--panel-2); color: var(--ink); }
.ctxbar button.on { background: var(--accent-soft); color: var(--ink); }
.ctxbar button.danger:hover { background: rgba(248,113,113,.15); color: #fca5a5; }
.ctxbar button.done { background: var(--grad); color: #fff; }
.ctxbar button.done:hover { filter: brightness(1.06); color: #fff; }
.ctxbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }
.ctxbar .cdot { width: 16px; height: 16px; border-radius: 999px; border: 1px solid var(--line-2); }

/* popover ricerca immagini */
.imgpanel {
  position: absolute; z-index: 45; width: min(420px, 92%); max-height: 70%; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 14px;
  box-shadow: 0 22px 50px -20px rgba(0,0,0,.75);
}
.imgpanel[hidden] { display: none !important; }
.imgpanel .row { display: flex; gap: 8px; margin-bottom: 12px; }
.imgpanel input {
  flex: 1; font-family: var(--sans); font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--inset);
}
.imgpanel input:focus { outline: none; border-color: var(--accent); }
.imgpanel .grid-imgs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.imgpanel .grid-imgs img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.imgpanel .grid-imgs img:hover { border-color: var(--accent); }
.imgpanel .hint { color: var(--ink-faint); font-size: 13px; margin: 4px 0 0; }

/* ---- pannellino modifica testo (mobile) ---- */
.txt-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--panel); border-top: 1px solid var(--line-2);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -14px 34px -16px rgba(0,0,0,.7);
}
.txt-sheet[hidden] { display: none !important; }
.txt-sheet-head { display: flex; align-items: center; justify-content: space-between; }
.txt-sheet-title { font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.txt-sheet-cancel { background: transparent; border: 0; color: var(--ink-soft); font-family: var(--sans); font-weight: 600; font-size: 14px; cursor: pointer; padding: 4px 6px; }
.txt-sheet-input {
  width: 100%; resize: none; font-family: var(--sans); font-size: 16px; line-height: 1.4; color: var(--ink);
  background: var(--inset); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 48px; max-height: 32vh;
}
.txt-sheet-input:focus { outline: none; border-color: var(--accent); }
.txt-sheet-save { align-self: stretch; }

/* ---- responsive ---- */
@media (max-width: 820px) {
  html { height: 100%; overflow: hidden; }
  body {
    position: fixed; top: var(--vv-top, 0px); left: 0; right: 0;
    height: var(--app-h, 100dvh); overflow: hidden; overscroll-behavior: none;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  }
  input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
  .mobile-tabs { display: flex; padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px)); }
  body.sheet-open .mobile-tabs { display: none; }
  .mtab { padding: 11px 0; }
  .topbar { padding: 10px 12px; flex-shrink: 0; }
  .tag { display: none; }
  .brand-logo { height: 24px; }
  .top-actions { gap: 6px; }
  .top-actions .btn { padding: 7px 10px; font-size: 12.5px; }
  .btn-text { display: none; }
  .btn-ic { display: inline-block; vertical-align: middle; }
  #settingsBtn { padding: 7px 9px; }
  .proj-btn-label { max-width: 110px; }
  .proj-menu { min-width: 210px; }

  .grid { grid-template-columns: 1fr; grid-template-rows: 1fr; min-height: 0; }
  .chat { border-right: 0; min-height: 0; }
  body:not(.view-preview) .preview { display: none; }
  body.view-preview .chat { display: none; }

  .messages { padding: 16px; overscroll-behavior: contain; }
  .composer textarea { max-height: 30vh; }

  .toolbar { padding: 10px 12px; gap: 8px 10px; }
  .toolbar .actions { gap: 6px; }
  .toolbar .actions .btn { padding: 7px 10px; font-size: 12.5px; }
}
@media (max-width: 380px) {
  .proj-btn-label { max-width: 76px; }
  .top-actions .btn, .toolbar .actions .btn { font-size: 12px; padding: 6px 9px; }
}
