html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: #111;
  background: #f6f7f9;
  overflow: hidden;
}

:root{
  --side-btn-w: 110px;
  --ctrl-h: 34px;
  /* Shared width for FILE column + header hint slot */
  --results-col-file-w: 160px;
}


#app {
  display: flex;
  height: 100%;
  overflow: hidden;
}



/* draggable splitter between sidebar and 3D canvas */
#splitter {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  flex: 0 0 auto;
}
#splitter:hover {
  background: rgba(0,0,0,0.06);
}
#splitter.dragging {
  background: rgba(0,0,0,0.10);
}
body.resizing {
  cursor: col-resize;
  user-select: none;
}

#sidebar {
  width: 340px;
  min-width: 260px;
  max-width: 75vw;
  background: #ffffff;
  border-right: 1px solid #e6e6e6;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1.2px;
}

.section {
  border: 1px solid #ececec;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.section.grow { flex: 1; display:flex; flex-direction:column; min-height: 0; }

.title {
  font-weight: 700;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: center;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Collapsible sections (click the title) */
.section.collapsed > :not(.title) { display: none; }
.section.collapsed .title { margin-bottom: 0; }
.section.grow.collapsed { flex: 0 0 auto; }
.title::after {
  content: "▾";
  font-size: 12px;
  opacity: 0.65;
}
.section.collapsed .title::after { content: "▸"; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Parametri: KEY + input on the same line */
.kvrow{
  display: flex;
  align-items: center;
  gap: 8px;
}
.keylabel{
  flex: 0 0 auto;
  width: var(--side-btn-w);
  font-size: 12px;
  font-weight: 700;
  color: #444;
  text-align: right;
}
.kvrow input[type="text"]{
  flex: 1 1 auto;
  width: 100%;
}

/* Parametri: compact vertical spacing like Sessions + grey when pending */
#paramsFormMount .kvrow{
  margin-top: 0 !important;
}

#paramsFormMount .kvrow input[type="text"]{
  height: var(--ctrl-h);
  padding: 6px 10px;
  box-sizing: border-box;
}

input.pending-param{
  color: #888;
}

/* Upload row: button + progress bar (same line) */
.row.upload-row{
  align-items: center;
  gap: 10px;
}
.row.upload-row #btnUpload{
  flex: 0 0 auto;
}

/* Right side of upload row: progress + reload button (like "Aggiorna lista id") */
.row.upload-row .upload-right-row{
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.row.upload-row .upload-right-row .task-status{
  flex: 1 1 auto;
  height: var(--ctrl-h);
  min-width: 140px;
}

input[type="text"] {
  flex: 1;
  border: 1px solid #dadada;
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

input[type="file"] {
  width: 100%;
}

/* Give the same "dignity" to 'Scegli file' and 'Carica' */
#btnUpload{
  width: var(--side-btn-w);
  height: var(--ctrl-h);
  padding: 0 12px;
}
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button{
  width: var(--side-btn-w);
  height: var(--ctrl-h);
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 0 12px;
  background: #f9f9f9;
  cursor: pointer;
  text-align: center;
  margin-right: 10px;
}
input[type="file"]::file-selector-button:hover,
input[type="file"]::-webkit-file-upload-button:hover{
  background: #f1f1f1;
}

button {
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #f9f9f9;
  cursor: pointer;
  text-align: center;
}

button:hover { background: #f1f1f1; }

/* Small square "icon" buttons on the right of inputs/bars */
#btnLoadSessions,
#btnReload{
  width: var(--ctrl-h);
  height: var(--ctrl-h);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
#btnLoadSessions:disabled,
#btnReload:disabled{ opacity: 0.45; cursor: default; }

.muted { color: #666; }
.small { font-size: 12px; }

.list {
  border: 1px solid #ededed;
  border-radius: 10px;
  overflow: auto;
  max-height: 160px;
  background: #fbfbfb;
}

.list .item {
  padding: 8px 10px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  text-align: center;
  user-select: none;
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.list .item:last-child { border-bottom: none; }

.list .item:hover { background: #f4f6ff; }

.badge {
  font-size: 11px;
  color: #333;
  padding: 2px 6px;
  border-radius: 999px;
  background: #ececec;
  border: 1px solid #e0e0e0;
}

.results {
  border: 1px solid #ededed;
  border-radius: 10px;
  background: #fbfbfb;
  overflow: hidden; /* delegate scrolling to .results-table-wrap */
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.rrow {
  display:grid;
  grid-template-columns: 56px 18px 1fr;
  gap: 8px;
  align-items:center;
  padding: 6px 10px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
}

.rrow:last-child { border-bottom: none; }

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
}

.count {
  font-variant-numeric: tabular-nums;
  text-align:right;
  color:#111;
}

.path {
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#canvasWrap {
  position:absolute;
  inset: 0;
}

#hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.8);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  font-size: 12px;
}

.ctx-menu {
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.12);
}

.ctx-menu button {
  width: 100%;
  text-align:left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
}

.ctx-menu button:hover {
  background:#f2f2f2;
}


/* ---------- Results table (sticky header + horizontal scroll) ---------- */
.results {
  overflow: hidden; /* scrolling handled by .results-table-wrap */
}

.results table {
  border-collapse: collapse;
  width: max-content;   /* enables horizontal scroll when needed */
  min-width: 100%;
  background: #fbfbfb;
}

.results thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #ffffff;
  border-bottom: 1px solid #e6e6e6;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #333;
}

.results th, .results td {
  /*padding: 6px 10px;*/
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap; /* show full row on one line; scroll horizontally */
  font-size: 13px;
}

.results tbody tr:hover {
  background: var(--ui-results-hover-bg, #f4f6ff);
}

.results tbody tr.selected {
  background: var(--ui-results-selected-bg, #dbe8ff);
}

/* Highlight selected column (pilot key) */
.results thead th.col-selected{
  /* do NOT fill the whole header cell (avoids "vertical" highlight up to the label) */
  background: #ffffff;
  box-shadow: inset 0 -2px 0 var(--ui-results-selected-bg, #dbe8ff);
}
.results tbody td.col-selected{
  background: var(--ui-results-selected-bg, #dbe8ff);
}

/* Avoid dark focus outline when navigating with keyboard arrows */
#results:focus,
#results:focus-visible,
#results .results-table-wrap:focus,
#results .results-table-wrap:focus-visible,
#results table:focus,
#results table:focus-visible,
#results th:focus,
#results th:focus-visible,
#results td:focus,
#results td:focus-visible,
#results tr:focus,
#results tr:focus-visible{
  outline: none;
}


.results .swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
}

/* ---------- 3D label ---------- */
.file-label {
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.18);
  background: rgba(255,255,255,0.92);
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
  font-size: 12px;
  color: #111;
  white-space: nowrap;
  pointer-events: none;
}

.file-label .name {
  font-weight: 700;
  margin-right: 6px;
}

.file-label .count {
  font-variant-numeric: tabular-nums;
  color: #333;
}


/* ---------- Session delete button ---------- */
.del-btn{
  width: 34px;
  height: 34px;
  line-height: 20px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.18);
  background: #fff;
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  padding: 0;
}
.del-btn:hover{
  background: #ffecec;
}


/* ---------- Results table wrapper (scroll + sticky header) ---------- */
.results-table-wrap{
  flex: 1;
  min-height: 180px; /* ~ header + at least 6 rows */
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  background: #fff;
}

.results-table{
  width: max-content;          /* keep columns as tight as possible */
  min-width: 100%;            /* but fill the container when it can */
  border-collapse: collapse;
  min-width: 660px;           /* still enables horizontal scroll when needed */
}

/* Make cells more compact */
.results-table th,
.results-table td{
  padding: 1px 1px;
  font-size: 12px;
}

.results-table thead th{
  font-size: 11px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.10);
  cursor: pointer;
  text-align: center;
  user-select: none;
}

.results-table .pilot-mark{
  display: inline-block;
  width: 12px;
  margin-right: 4px;
  opacity: 0.18;
}
.results-table .pilot-mark.on{ opacity: 1; }

.results-table .col-callers,
.results-table .col-callees,
.results-table .col-frequency,
.results-table .col-cnc,
.results-table .col-plc,
.results-table .col-mmac,
.results-table .col-gud,
.results-table .col-math,
.results-table .col-row,
.results-table .col-prt,
.results-table .col-dsc,
.results-table .col-dta{
  width: flex;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/*18*2px*/
.results-table .col-file{
  width: var(--results-col-file-w);
  min-width: var(--results-col-file-w);
  max-width: var(--results-col-file-w);
}
.results-table td.col-file .file-name{
  display: inline-block;
  max-width: calc(var(--results-col-file-w) - 22px); /* swatch + small gap */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.results-table .col-ext{  width: flex; }/*70px*/
.results-table .col-dir{  min-width: flex; }/*180px*/

.results-table .dir-text{
  color: rgba(0,0,0,0.65);
  white-space: nowrap;
}


/* ---------- Guide badge (top-right) ---------- */
.guide-badge{
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10000;

  /* Match the look/height of small action buttons (e.g. "Aggiorna analisi") */
  height: var(--ctrl-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;

  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 0 10px;
  background: #f9f9f9;
  cursor: pointer;

  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: #111;
  text-decoration: none;
  user-select: none;
}
.guide-badge:hover{
  background: #f1f1f1;
}
.guide-badge:active{
  transform: translateY(1px);
}


/* ---------- File label with sources list ---------- */
.file-label{
  max-width: 340px;
  padding: 8px 10px;
}

.file-label .head{
  display:flex;
  align-items: baseline;
  gap: 8px;
}

.file-label .sources-title{
  margin-top: 0;
  font-size: 11px;
  opacity: 0.75;
}

.file-label .sources-list{
  margin: 6px 0 0 0;
  padding-left: 16px;
  max-height: 160px;
  overflow: auto;
}

.file-label .sources-list li{
  margin: 2px 0;
  line-height: 1.2;
  white-space: nowrap;
}

.file-label .src-count{
  display:inline-block;
  min-width: 22px;
  text-align: right;
  margin-right: 8px;
  font-weight: 600;
}

.file-label .more{
  opacity: 0.7;
  list-style: none;
  margin-left: -16px;
}


/* Sessions (Macchine) list */
.list .item.session-item{
  height: var(--ctrl-h);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
}

.list .item.session-item .session-main{
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.list .item.session-item .session-id{
  font-weight: 600;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list .item.session-item .session-sep{
  opacity: 0.6;
  flex: 0 0 auto;
}

.list .item.session-item .session-root,
.list .item.session-item .session-file{
  font-size: 12px;
  color: #666;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list .item.session-item.active{
  background: var(--ui-session-active-bg, #dbe8ff);
  border-left: 4px solid var(--ui-session-accent, #18a957);
  padding-left: 6px; /* 6 + 4 = 10 (keeps alignment) */
}

.list .item.session-item.active:hover{
  background: var(--ui-session-active-hover-bg, #cfe0ff);
}

.session-actions{ display:flex; gap:6px; align-items:center; }

/* Session: keep 'mac (editabile)' compact (avoid growing) */
.list .item.session-item input.session-mac{
  width: 120px;
  flex: 0 0 120px;
  max-width: 120px;
  height: var(--ctrl-h);
  padding: 0 8px;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  font-size: 12px;
  box-sizing: border-box;
}
.list .item.session-item input.session-mac:focus{
  outline: none;
  border-color: #9bbcff;
  box-shadow: 0 0 0 2px rgba(155,188,255,0.35);
}


.session-actions .reload-btn,
.session-actions .del-btn{
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.18);
  background: #fff;
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  line-height: 20px;
}

.session-actions .reload-btn:hover{
  background: #eef7ff;
}

.session-actions .reload-btn{
  display: none;
  font-weight: 700;
}

/* Reload visible only on active session */
.list .item.session-item .session-actions .reload-btn{
  display:none;
}
.list .item.session-item.active .session-actions .reload-btn{
  display:inline-block;
}

/* Busy mode: lock sidebar interactions during upload/reprocess, keep scene interactive */
/* Upload/Reprocess progress bar */
.progress-wrap{
  width: 100%;
  height: 8px;
  background: #e6e6e6;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0;
}
.progress-wrap.hidden{ display: none; }
.progress-bar{
  height: 100%;
  width: 0%;
  background: var(--ui-session-active-bg, #dbe8ff);
  transition: width 120ms linear;
}

/* Task status/progress bar: always visible, text inside */
.task-status{
  position: relative;
  width: 100%;
  height: var(--ctrl-h);
  margin-top: 0;
  background: #fff;
  border: 1px solid #dadada;
  border-radius: 8px;
  overflow: hidden;
}
.task-fill{
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--ui-session-active-bg, #dbe8ff);
  transition: width 120ms linear;
}

/* Subtle activity stripes while a long task is running (keeps UI "alive" even when markers are slow) */
.task-status.busy .task-fill{
  background-image: linear-gradient(
    45deg,
    rgba(255,255,255,.22) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255,255,255,.22) 50%,
    rgba(255,255,255,.22) 75%,
    transparent 75%,
    transparent
  );
  background-size: 16px 16px;
  animation: task-stripes 1200ms linear infinite;
}

@keyframes task-stripes{
  0%   { background-position: 0 0; }
  100% { background-position: 32px 0; }
}
.task-text{
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  user-select: none;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #111;
  font-weight: 600;
}

.progress-wrap.indeterminate .progress-bar{
  width: 40%;
  animation: indeterminate-bar 900ms ease-in-out infinite;
}

.task-status.indeterminate .task-fill{
  width: 40%;
  animation: task-indeterminate 900ms ease-in-out infinite;
}
@keyframes task-indeterminate{
  0% { transform: translateX(-600%); }
  50% { transform: translateX(60%); }
  100% { transform: translateX(200%); }
}

@keyframes indeterminate-bar{
  0%   { transform: translateX(-60%); }
  50%  { transform: translateX(90%); }
  100% { transform: translateX(-60%); }
}

/* Full-width for Importa cartella inputs */
#extsInput,
#cncKeysInput,
#plcKeysInput,
#mathKeysInput,
#gudKeysInput{
  width: 100%;
  box-sizing: border-box;
}

/* display: block; */

/* Risultati: vocazione (tipo suggerito) */
.results-type { margin-left: 10px; white-space: nowrap; text-align: left; }
.results-type .results-file-slot{
  display: inline-block;
  width: var(--results-file-slot-w, var(--results-col-file-w, 18ch));
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  vertical-align: bottom;
}
