  :root {
    --sidebar-w: 360px;
    --ps-orange: #F58220;
    --ps-orange-soft: #FFA85C;

    --ps-blue: #3E6FB6;
    --ps-blue-soft: #E8F0FB;

    --ps-green: #2E8B57;
    --ps-red: #C0392B;

    --bg-main: #F5F3EF;   /* grigio caldo */
    --card-bg: #FFFFFF;
    --text-main: #2E2E2E;
    --text-soft: #6C757D;

  }

  html, body { height: 100%; }
  body { 
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--bg-main);
    margin: 2rem; 
    overflow: hidden; 
  }

  /* GRID: deve avere ALTEZZA FISSA, non min-height */
  .app-shell {
    height: 100vh;            /* 🔥 chiave: blocca la UI nella viewport */
    display: grid;
    grid-template-columns: 1fr minmax(300px, var(--sidebar-w));
    gap: 1rem;
    padding: 0rem 0rem 3rem 0rem;
    box-sizing: border-box;

    min-height: 0;            /* 🔥 permette ai figli di “shrinkare” */
  }

  @media (max-width: 992px) {
    .app-shell { grid-template-columns: 1fr; }
  }

  /* IMPORTANTISSIMO su grid children: evita che spingano oltre */
  .app-shell > * {
    min-height: 0;
  }

  /* Card */
  .card{
    border: 0;
    border-radius: 12px;
  }
  .card-header{
    background: #fff;
    border-bottom: 1px solid rgba(0,0,0,.06);
  }

 /* =========================
   PolyShaper Buttons System
   ========================= */

  .btn{
    border-radius: 10px;
    font-weight: 700;
    letter-spacing: .2px;
  }

  .btn .btn-icon{ margin-right: .5rem; }

  /* Focus accessibile (utile per target 40-60 + tastiera) */
  .btn:focus-visible{
    outline: 3px solid rgba(62,111,182,.35); /* ps-blue soft */
    outline-offset: 2px;
    box-shadow: none;
  }

  /* ---------- 1) PRIMARY (ARANCIONE)
    SOLO: "Prepara il taglio"
    - in hover resta pieno, leggermente più scuro
    - disabled solo più opaco
  */
  .btn-ps-primary{
    background: var(--ps-orange);
    border: 1px solid var(--ps-orange);
    color: #fff;
  }

  .btn-ps-primary:hover{
    background: #e87412;                
    border-color: #e87412;
    color: #fff;
  }

  .btn-ps-primary:active{
    transform: translateY(1px);
  }

  /* Disabled: solo più opaco */
  .btn-ps-primary:disabled,
  .btn-ps-primary.disabled{
    opacity: .55;
    cursor: not-allowed;
    background: #e87412;               
    border-color: #e87412;
    color: #fff;
  }

  /* ---------- 2) SECONDARY (GRIGIO)
    PER: "Passa a Wi-Fi", "Cambia rete Wi-Fi", settaggi sistema
    - grigio soft, non troppo “tecnico”
  */
  .btn-ps-secondary{
    background: #fff;
    border: 1px solid rgba(0,0,0,.18);
    color: var(--text-main);
  }

  .btn-ps-secondary:hover{
    background: rgba(0,0,0,.04);
    border-color: rgba(0,0,0,.22);
  }

  .btn-ps-secondary:active{
    transform: translateY(1px);
  }

  .btn-ps-secondary:disabled,
  .btn-ps-secondary.disabled{
    opacity: .55;
    cursor: not-allowed;
  }

  /* Variante: secondary "soft fill" se vuoi evidenziare senza usare arancione */
  .btn-ps-secondary-soft{
    background: rgba(62,111,182,.08);   /* ps-blue soft */
    border: 1px solid rgba(62,111,182,.18);
    color: #1f3f73 !important;
  }
  .btn-ps-secondary-soft:hover{
    background: rgba(62,111,182,.12);
  }

  .btn-ps-secondary:disabled,
  .btn-ps-secondary.disabled{
    opacity: .55;
    cursor: not-allowed;
    background: rgba(62,111,182,.08);   /* ps-blue soft */
    border: 1px solid rgba(62,111,182,.18);
    color: #1f3f73 !important;
  }

  /* ---------- 3) DANGER (OUTLINE)
    PER: Logout / Disconnetti (+ eventualmente Nuovo SVG)
    - resta outline anche in hover (solo leggero fill)
  */
  .btn-ps-danger{
    background: #fff;
    border: 1px solid rgba(192,57,43,.55);
    color: #c0392b;
  }

  .btn-ps-danger:hover{
    background: rgba(192,57,43,.06);
    border-color: rgba(192,57,43,.75);
    color: #b53126;
  }

  .btn-ps-danger:active{
    transform: translateY(1px);
  }

  .btn-ps-danger:disabled,
  .btn-ps-danger.disabled{
    opacity: .55;
    cursor: not-allowed;
    border: 1px solid rgba(192,57,43,.55);
    color: #c0392b;
  }

  /* Consistenza dimensioni nei gruppi */
  .btn-ps-block{
    width: 100%;
    padding: .8rem 1rem;
  }

  .btn-ps-sm{
    padding: .45rem .75rem;
    font-size: .9rem;
  }

  /* Jog buttons: centratura perfetta icona */
  .jog-grid .btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;              /* elimina padding bootstrap */
    line-height: 1;          /* evita shift verticale */
  }

  .jog-grid .btn i{
    margin: 0 !important;    /* toglie il margin-right globale */
    line-height: 1;
    font-size: 18px;         /* uniforme */
  }



  /* Workspace */
  .workspace {
    background: #fff;
    border-radius: .5rem;
    box-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 10px 30px rgba(0,0,0,.06);
    padding: 1rem;

    display: flex;
    flex-direction: column;

    min-height: 0;           /* 🔥 fondamentale */
  }

  .workspace-bar {
    position: relative;
  }
  
  .workspace-left,
  .workspace-right {
    flex: 1;
  }
  
  .workspace-center {
    flex: 0 0 auto;
  }
  
  .workspace-logo {
    height: 32px;
    cursor: pointer;
    transition: transform .2s ease, opacity .2s ease;
  }
  
  .workspace-logo:hover {
    transform: scale(1.05);
    opacity: .85;
  }

  .workspace-logo:active {
    transform: scale(0.96);
  }
  

  /* Area editor interna: prende tutto lo spazio disponibile sotto l’header */
  .work-canvas {
    flex: 1;
    min-height: 0;           /* 🔥 fondamentale */
    position: relative;

    border: 1px dashed #ced4da;
    border-radius: .5rem;
    overflow: hidden;        /* niente scroll dentro */
    background: #fff;        /* base */
  }

  /* di default niente scacchiera */
  .work-canvas::before { content: none; }

  /* editor container sopra la scacchiera */
  #svgEditor {
    position: absolute;
    inset: 0;
    z-index: 10;
  }

  /* Dropzone deve stare sopra lo sfondo */
  .dropzone {
    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    color: #6c757d;
    text-align: center;
    cursor: pointer;
    padding: 2rem;
    user-select: none;
    z-index: 30;
  }

  .dropzone.dragover {
    outline: 2px dashed #0d6efd;
    outline-offset: -8px;
    background: rgba(13,110,253,0.06);
    color: #0d6efd;
  }

  /* SVG full viewport */
  .editor-svg {
    width: 100%;
    height: 100%;
    display: block;

    user-select: none;
    cursor: grab;
  }
  .editor-svg:active { cursor: grabbing; }

  #rulerTop, #rulerLeft{
    position:absolute;
    background:#3a3a3a;
    color:#eaeaea;
    font-size:11px;
    user-select:none;
    z-index:5;
    overflow:hidden;
  }

  #rulerTop{
    left:28px; right:16px; top:0;
    height:28px;
    border-bottom:1px solid rgba(255,255,255,.15);
  }

  #rulerLeft{
    top:28px; bottom:16px; left:0;
    width:28px;
    border-right:1px solid rgba(255,255,255,.15);
  }

  .ruler-track{
    position:relative;
    width:100%;
    height:100%;
  }

  /* Ticks X */
  .ruler-x-tick{
    position:absolute;
    bottom:0;
    width:1px;
    background:rgba(255,255,255,.35);
  }
  .ruler-x-tick.minor{ height:6px;  background:rgba(255,255,255,.25); }
  .ruler-x-tick.mid  { height:10px; background:rgba(255,255,255,.35); }
  .ruler-x-tick.major{ height:14px; background:rgba(255,255,255,.55); }

  /* Label X */
  .ruler-x-label{
    position:absolute;
    top:4px;
    transform: translateX(-50%);
    padding:0 4px;
    white-space:nowrap;
    color:#f1f1f1;
    font-size:11px;
  }

  /* Ticks Y */
  .ruler-y-tick{
    position:absolute;
    right:0;
    height:1px;
    background:rgba(255,255,255,.35);
  }
  .ruler-y-tick.minor{ width:6px;  background:rgba(255,255,255,.25); }
  .ruler-y-tick.mid  { width:10px; background:rgba(255,255,255,.35); }
  .ruler-y-tick.major{ width:14px; background:rgba(255,255,255,.55); }

  /* Label Y */
  .ruler-y-label{
    position:absolute;
    left:4px;
    transform: translateY(-50%);
    padding:2px 0;
    white-space:nowrap;
    color:#f1f1f1;
    font-size:11px;
  }

  .editor-scrollbar{
    position:absolute;
    z-index: 20;
    background: rgba(0,0,0,.15);
  }

  .editor-scrollbar.h{
    left: 28px; right: 16px; bottom: 0;
    height: 16px;
    display:flex; align-items:center;
  }
  .editor-scrollbar.v{
    top: 28px;
    bottom: 16px;
    right: 0;
    width: 16px;
    display:flex;
    align-items: stretch;
    justify-content: center;
    background: rgba(0,0,0,.15);
  }

  .editor-scrollbar input[type="range"]{
    width: 100%;
    height: 100%;
    margin: 0;
    appearance: none;
    background: transparent;
  }
  .editor-scrollbar.v input[type="range"]{
    width: 16px;
    height: 100%;
    margin: 0;
    writing-mode: bt-lr;          /* fallback */
    writing-mode: vertical-rl;    /* standard */
    direction: rtl;               /* fa andare su->giù naturale */
    appearance: none;
    background: transparent;
  }

  /* thumb */
  .editor-scrollbar input[type="range"]::-webkit-slider-thumb{
    -webkit-appearance:none;
    width: 24px;
    height: 12px;
    background: rgba(255,255,255,.75);
    border-radius: 6px;
    cursor: pointer;
  }
 .editor-scrollbar.v input[type="range"]::-webkit-slider-thumb{
    -webkit-appearance:none;
    width: 12px;
    height: 28px;
    background: rgba(255,255,255,.75);
    border-radius: 6px;
    cursor: pointer;
  }

  /* viewport si sposta per lasciare spazio ai righelli */
  /* viewport (di base) */
  .editor-viewport{
    position:absolute;
    top:28px;
    left:28px;
    right:16px;
    bottom:16px;
    overflow:hidden;
    z-index: 5;
  }

  /* stato EMPTY: scacchiera */
  .work-canvas.is-empty .editor-viewport{
    background-size: 24px 24px;
    background-image:
      linear-gradient(45deg, rgba(0,0,0,.04) 25%, transparent 25%),
      linear-gradient(-45deg, rgba(0,0,0,.04) 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, rgba(0,0,0,.04) 75%),
      linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.04) 75%);
    background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  }

  /* stato LOADED: grigio inkscape */
  .work-canvas.is-loaded .editor-viewport{
    background:#cfcfcf;
  }


  /* dentro masterSvg */
  #bgRect, #paperRect, #previewLayer { pointer-events: none; }

  #selectionRect{
    fill: none;
    stroke: #0d6efd;
    stroke-width: 1.2;
    stroke-dasharray: 6 4;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
  }  

  /* Sidebar */
  .sidebar {
    display: flex;
    flex-direction: column;  
    height: 100%;           /* prende tutta l’altezza della grid */
    min-height: 0;          /* IMPORTANTISSIMO per scroll interno */
  }

  .sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }  

  .sidebar .card { box-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 10px 30px rgba(0, 0, 0, .06); }

  .sidebar .bottom-actions {
    position: sticky;
    padding: 1rem;
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    border: 1px solid rgba(0,0,0, 0.1);
    border-radius: 7px;
    background-color: #fff;
    box-shadow: 0 -6px 12px rgba(0, 0, 0, 0.08);
  }

  #advStartContainer.adv-grow {
    flex: 1 1 auto;     /* prende lo spazio rimanente nella sidebar-scroll */
    min-height: 220px;  /* evita che diventi troppo piccolo */
  }
  
  /* card full-height */
  #advStartContainer .adv-card {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  
  /* solo media cliccabile */
  #advStartContainer .adv-media {
    flex: 1 1 auto;
    border-radius: 14px;
    overflow: hidden;
    background: #f3f3f3;
  }
  
  #advStartContainer .adv-media img,
  #advStartContainer .adv-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  
  /* label discreta */
  #advStartContainer .adv-label {
    font-size: 12px;
    color: rgba(255,255,255,.8);
    background: rgba(0,0,0,.45);
    padding: 6px 10px;
    border-radius: 999px;
    position: absolute;
    left: 10px;
    top: 10px;
    backdrop-filter: blur(6px);
  }
  
  .ps-swal-popup {
    border-radius: 16px;
    padding: 18px;
  }
  
  .ps-swal-title {
    font-weight: 700;
  }
  

  .kv { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; }
  .kv .k { color:#6c757d; }
  .kv .v { font-weight: 600; }

  .jog-grid {
    display: grid;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
    gap: 6px;
    justify-content: center;
    align-items: center;
  }
  
  .jog-grid button {
    width: 42px;
    height: 42px;
    padding: 0;
    font-size: 18px;
  }
  
  /* Terminal */
  .terminal-log {
    background: #101317;
    color: #e6edf3;
    min-height: 40vh;
    max-height: 70vh;
    padding: 12px 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12.5px;
    line-height: 1.45;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .terminal-log .rx { color: #76c7ff; }   /* ricezione */
  .terminal-log .tx { color: #9ae6b4; }   /* trasmissione */
  .terminal-log .err { color: #ff6b6b; }  /* errori */
  .terminal-log .sys { color: #c9d1d9; }  /* info sistema */

  .loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
  }
  
  .loading-overlay__content {
    text-align: center;
    font-size: 1.1rem;
  }
  
  /* spinner minimal */
  .loading-overlay .spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .d-none { display: none !important; }
  
  /* Modal wifi */
  .wifi-dots span{
    opacity: .2;
    animation: wifiDot 1s infinite;
    display:inline-block;
    margin-left:1px;
  }
  .wifi-dots span:nth-child(2){ animation-delay: .2s; }
  .wifi-dots span:nth-child(3){ animation-delay: .4s; }

  @keyframes wifiDot{
    0%, 20% { opacity:.2; transform: translateY(0); }
    50%     { opacity:1;  transform: translateY(-1px); }
    80%,100%{ opacity:.2; transform: translateY(0); }
  }

  .lang-menu {
    min-width: 60px;
    padding: 4px;
  }
  
  .lang-menu .dropdown-item {
    padding: 6px;
    text-align: center;
  }
  
  .lang-menu img {
    border-radius: 2px;
  }
