/* Console (console.html) e File manager (filemanager.html).
   Solo le regole di questi componenti: pulsanti, campi, schede, tabelle e
   lightbox vengono da Bootstrap e da style.css. */

/* ------- console a tutta larghezza ------- */

body.console .sm-main {
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .55rem 1rem;
  border-bottom: 1px solid var(--sm-line);
  background: #fff;
  flex: none;
}
.console-head .breadcrumb { margin-bottom: 0; }
#preview-status { font-size: .82rem; white-space: nowrap; }
.console-tools { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }

.console-grid {
  flex: 1;
  display: grid;
  grid-template-columns: var(--cc-left-w, minmax(340px, 44%)) 6px 1fr;
  min-height: 0;
}

/* ------- riquadri ridimensionabili: maniglie di trascinamento ------- */

.cc-handle-col, .cc-handle-row {
  flex: none;
  position: relative;
  background: transparent;
  touch-action: none;
  z-index: 2;
}
.cc-handle-col { cursor: col-resize; }
.cc-handle-row { height: 6px; cursor: row-resize; }
.cc-handle-col::after, .cc-handle-row::after {
  content: "";
  position: absolute;
  background: var(--sm-line);
  transition: background .1s;
}
.cc-handle-col::after { top: 0; bottom: 0; left: 50%; width: 1px; margin-left: -.5px; }
.cc-handle-row::after { left: 0; right: 0; top: 50%; height: 1px; margin-top: -.5px; }
.cc-handle-col:hover::after, .cc-handle-col.cc-attiva::after { background: var(--sm-blue); width: 2px; margin-left: -1px; }
.cc-handle-row:hover::after, .cc-handle-row.cc-attiva::after { background: var(--sm-blue); height: 2px; margin-top: -1px; }

.console-left {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sm-line);
  background: #fff;
  min-width: 0;
  min-height: 0;
}

/* schede in cima alla colonna: File manager / Plugin / Temi / Produzione,
   oppure Editor Template / Funzioni AI per le app TV */
.xp-tabs { flex: none; padding: 0 .5rem; background: #fff; }
.cc-tabs { padding-left: .3rem; }

/* console di un'app Smart TV: editor del template di Polly in un iframe */
.tpl-pane {
  flex: 1;
  display: flex;
  min-height: 0;
  border-bottom: 1px solid var(--sm-line);
  background: #fff;
}
.tpl-pane iframe { flex: 1; width: 100%; border: none; }

/* esplora file e le sue schede: si nasconde in blocco quando e' aperto
   l'editor del template */
.xp-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ------- pannello Claude: output, modello, input ------- */

.claude-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--sm-line);
  background: #fff;
}
/* la chat e il file manager si dividono l'altezza: ognuno resta leggibile
   anche spinto al minimo */
.console-left.split .claude-pane, .console-left.split .xp-zone { min-height: 90px; }
.claude-out {
  flex: 1;
  overflow-y: auto;
  padding: .9rem 1rem;
  font-size: .9rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.cc-user {
  color: var(--bs-primary);
  font-weight: 600;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--sm-line);
  padding-top: .55rem;
}
.cc-user:first-child { border-top: none; padding-top: 0; }
.cc-text { white-space: pre-wrap; word-break: break-word; }
.cc-tool {
  color: var(--sm-muted);
  font-size: .8rem;
  font-family: ui-monospace, Consolas, "Cascadia Mono", monospace;
  word-break: break-all;
}
.cc-err { color: var(--sm-err); white-space: pre-wrap; word-break: break-word; }
.cc-notice { color: var(--sm-muted); font-size: .8rem; font-style: italic; }

.cc-meta {
  flex: none;
  border-top: 1px solid var(--sm-line);
  padding: .5rem .9rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.cc-model {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--sm-muted);
}
.cc-model .form-select { width: auto; font-size: .82rem; }

.claude-input {
  flex: none;
  border-top: 1px solid var(--sm-line);
  padding: .7rem .9rem;
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}
.claude-input textarea { flex: 1; min-width: 0; resize: none; font-size: .92rem; }
.claude-actions { display: flex; flex-direction: column; gap: .4rem; }

/* ------- anteprima ------- */

.console-right {
  position: relative;
  display: flex;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  background: #fff;
}
.console-right iframe { flex: 1; width: 100%; border: none; }

/* spinner sopra l'anteprima mentre il sito ricarica */
.preview-spin {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .6);
  z-index: 5;
}
.preview-spin::after {
  content: "";
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--sm-line);
  border-top-color: var(--bs-primary);
  animation: smspin .8s linear infinite;
}

/* app Smart TV: anteprima fissa in 16:9 su fondo nero e, sotto, i comandi
   di prova sui televisori */
.console-right.tv { flex-direction: column; background: var(--sm-bg); }
.tv-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .9rem;
}
.tv-stage iframe {
  flex: none;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: 100%;
  max-width: 100%;
  background: #000;
  border: 1px solid var(--sm-line);
  border-radius: var(--bs-border-radius);
}
.tv-actions {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .7rem .9rem;
  background: #fff;
  border-top: 1px solid var(--sm-line);
}
.tv-note {
  flex: 1 0 100%;
  margin: .1rem 0 0;
  font-size: .74rem;
  color: var(--sm-muted);
}

/* anteprima tablet e mobile: iframe a larghezza fissa su fondo grigio */
.console-right.w-tablet, .console-right.w-mobile { background: var(--sm-bg); }
.console-right.w-tablet iframe, .console-right.w-mobile iframe {
  flex: none;
  height: 100%;
  max-width: 100%;
  background: #fff;
  border-left: 1px solid var(--sm-line);
  border-right: 1px solid var(--sm-line);
}
.console-right.w-tablet iframe { width: 768px; }
.console-right.w-mobile iframe { width: 390px; }

/* ------- esplora file nella console ------- */

.xp-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
}
.xp-bar {
  padding: .55rem .8rem;
  border-bottom: 1px solid var(--sm-line);
  display: flex;
  flex-direction: column;
  gap: .45rem;
}
.xp-tools { display: flex; gap: .35rem; flex-wrap: wrap; }
.xp-msg { margin: .5rem .8rem 0; padding: .5rem .8rem; }
.xp-list {
  flex: 1;
  overflow-y: auto;
  padding: .3rem 0;
}
.xp-row {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .28rem .9rem;
  cursor: pointer;
  font-size: .85rem;
  user-select: none;
}
.xp-row:hover { background: var(--sm-bg); }
.xp-row.sel { background: rgba(0, 102, 204, .12); }
.xp-ico { flex: none; font-size: 1.25rem; line-height: 1; }
.xp-name { flex: 1; min-width: 0; word-break: break-all; }
.xp-size { flex: none; font-size: .78rem; }
.xp-list .hint { padding: .6rem .9rem; }

/* vista a griglia */
.xp-list.grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: .35rem;
  padding: .6rem;
}
.xp-list.grid .xp-row {
  flex-direction: column;
  justify-content: flex-start;
  width: 104px;
  padding: .55rem .3rem;
  border-radius: var(--bs-border-radius);
  text-align: center;
  gap: .2rem;
}
.xp-list.grid .xp-ico { font-size: 2.3rem; line-height: 1.1; }
.xp-list.grid .xp-name {
  flex: none;
  width: 100%;
  font-size: .72rem;
  line-height: 1.25;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.xp-list.grid .xp-size { display: none; }
.xp-list.grid .hint { width: 100%; }

/* editor in lightbox */
#xp-editor {
  height: 56vh;
  resize: vertical;
  font-size: .85rem;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}

/* visualizzatore multimediale */
.xp-viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.xp-viewer img, .xp-viewer video { max-width: 100%; max-height: 68vh; }
.xp-viewer audio { width: 100%; }

/* scelta della cartella nello spostamento */
.xp-move-list {
  border: 1px solid var(--sm-line);
  border-radius: var(--bs-border-radius);
  max-height: 300px;
  margin-top: .5rem;
}

/* elenco plugin e siti in produzione con pulsanti in riga */
.ext-row { cursor: default; }
.ext-row .btn { flex: none; }
.ext-row .xp-name small { display: block; font-size: .74rem; }

/* schede dei temi con anteprima */
.ext-themes {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: .7rem;
  padding: .8rem;
}
.ext-theme {
  width: 172px;
  border: 1px solid var(--sm-line);
  border-radius: var(--bs-border-radius);
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}
.ext-theme .shot {
  width: 100%;
  height: 118px;
  object-fit: cover;
  object-position: top;
  background: var(--sm-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  flex: none;
}
.ext-theme .ext-name {
  padding: .45rem .55rem .1rem;
  font-size: .78rem;
  line-height: 1.3;
  word-break: break-word;
  flex: 1;
}
.ext-theme .btn { margin: .45rem .55rem .55rem; align-self: flex-start; }

/* menu Modifica dell'editor (aperto e chiuso dal JS con hidden) */
.xp-menu { position: relative; }
.xp-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--sm-line);
  border-radius: var(--bs-border-radius);
  box-shadow: 0 10px 26px rgba(11, 32, 56, .16);
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: .3rem;
  z-index: 40;
}
.xp-menu-list button {
  border: none;
  background: none;
  color: var(--sm-ink);
  font: inherit;
  font-size: .86rem;
  text-align: left;
  padding: .45rem .7rem;
  border-radius: 6px;
}
.xp-menu-list button:hover { background: var(--sm-bg); }

/* spinner di caricamento nelle lightbox */
.xp-spin {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
}
.xp-spin::after {
  content: "";
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--sm-line);
  border-top-color: var(--bs-primary);
  animation: smspin .8s linear infinite;
}
@keyframes smspin { to { transform: rotate(360deg); } }

/* ------- file manager (pagina File) ------- */

.fm-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.fm-path {
  font-family: ui-monospace, Consolas, "Cascadia Mono", monospace;
  font-size: .85rem;
  color: var(--sm-muted);
  word-break: break-all;
}
.fm-path a { color: var(--bs-primary); text-decoration: none; }
.fm-path a:hover { text-decoration: underline; }

.fm-table .fm-name { cursor: pointer; word-break: break-all; }
.fm-table .fm-name:hover { color: var(--bs-primary); }
.fm-table .fm-name .bi { color: var(--sm-muted); margin-right: .3rem; }

#fm-editor {
  height: 62vh;
  resize: vertical;
  font-size: .84rem;
  line-height: 1.45;
  white-space: pre;
  tab-size: 2;
}

/* ------- schermi piccoli: colonne una sotto l'altra ------- */

@media (max-width: 991.98px) {
  body.console .sm-main {
    height: auto;
    min-height: calc(100vh - 3.5rem);
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  .console-grid { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .console-left { border-right: none; border-bottom: 1px solid var(--sm-line); }
  .cc-handle-col { display: none; }
}

/* ------- console delle app .NET: albero dei file, editor a schede, output ------- */
.console-right.ide {
  flex-direction: column;
  justify-content: flex-start;
  background: #fff;
}
.ide-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .45rem .7rem;
  border-bottom: 1px solid var(--sm-line);
  background: #f7f9fc;
  flex-wrap: wrap;
}
.ide-tree-head { display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .86rem; }
.ide-tools { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.ide-tools .form-select { width: auto; max-width: 260px; }
.ide-body {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 90px;
}
.ide-tree {
  overflow: auto;
  border-right: 1px solid var(--sm-line);
  padding: .3rem 0;
  font-size: .84rem;
  user-select: none;
}
.ide-node {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .18rem .5rem;
  white-space: nowrap;
  cursor: pointer;
  color: var(--sm-ink);
}
.ide-node:hover { background: var(--sm-bg); }
.ide-node.active { background: rgba(0, 102, 204, .12); color: var(--bs-primary); }
.ide-node.dim { color: var(--sm-muted); }
.ide-caret { width: .9rem; font-size: .7rem; color: var(--sm-muted); }
.ide-ico { color: #8a97a6; }
.ide-node.dir .ide-ico { color: #d8a72c; }
.ide-node.active .ide-ico { color: var(--bs-primary); }
.ide-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ide-tabs {
  flex: none;
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--sm-line);
  background: #f7f9fc;
  min-height: 2.1rem;
}
.ide-tab {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .5rem .35rem .8rem;
  font-size: .82rem;
  border-right: 1px solid var(--sm-line);
  cursor: pointer;
  color: var(--sm-muted);
  white-space: nowrap;
}
.ide-tab.active { background: #fff; color: var(--sm-ink); border-bottom: 2px solid var(--bs-primary); margin-bottom: -1px; }
.ide-tab.dirty span::after { content: " •"; color: #c47f00; }
.ide-tab-x { border: none; background: none; padding: 0 .1rem; color: var(--sm-muted); line-height: 1; border-radius: 4px; }
.ide-tab-x:hover { background: var(--sm-bg); color: var(--sm-ink); }
.ide-editor-wrap { flex: 1; position: relative; min-height: 0; }
.ide-editor {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: none; border-radius: 0;
  resize: none;
  font-size: .84rem;
  line-height: 1.5;
  white-space: pre;
  tab-size: 4;
  padding: .7rem .9rem;
}
.ide-editor:focus { box-shadow: none; }
.ide-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--sm-muted); font-size: .9rem; padding: 1rem; text-align: center;
}
.ide-status {
  flex: none;
  font-size: .76rem;
  color: var(--sm-muted);
  padding: .25rem .8rem;
  border-top: 1px solid var(--sm-line);
  min-height: 1.6rem;
}
.ide-status.err { color: var(--sm-err); }
.ide-out-head {
  flex: none;
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem .8rem;
  border-top: 1px solid var(--sm-line);
  background: #f7f9fc;
  font-size: .78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--sm-muted);
}
.ide-out {
  flex: none;
  height: 200px;
  min-height: 90px;
  margin: 0;
  padding: .6rem .8rem;
  overflow: auto;
  background: var(--sm-night);
  color: #d6e2f0;
  font-size: .78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}
@media (max-width: 991.98px) {
  .ide-body { grid-template-columns: 200px 1fr; }
}
