/* 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: minmax(340px, 44%) 1fr;
  min-height: 0;
}

.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;
}
.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); }
}
