:root{
  --bg: #0b0f14;
  --bg-elev: #0f131a;
  --panel: #11161d;
  --panel-2: #0d1218;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #2ea043;
  --accent-2: #1f6feb;
  --danger: #f85149;
  --card-border: #1f2630;
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body{
  margin:0; background: var(--bg); color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji;
}

/* ===== Desktop ===== */
#app{
  display:grid; grid-template-columns: 360px 1fr; gap: 16px;
  padding:16px;
}
.viewer{
  position:relative; border-radius: 16px; overflow:hidden;
  background: linear-gradient(180deg,#0a0e13,#090c11);
  box-shadow: var(--shadow);
  z-index:1;
}
.viewer canvas{ width:100%; height:100%; display:block; }

.sidebar.floating{
  position:relative;
  background: var(--bg-elev);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  /*max-height: calc(100vh - 32px);*/
  overflow: auto;
  backdrop-filter: blur(6px);
  z-index:2;
}
.sidebar h1{ margin: 0 0 12px; font-size: 18px; font-weight: 700; letter-spacing:.2px; }

.card{
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}
.card h2{ font-size: 13px; text-transform: uppercase; letter-spacing:.12em; color: var(--muted); margin: 0 0 10px; }

.row{
  display:grid; grid-template-columns: 1fr auto; gap:10px; align-items:center;
  margin:8px 0;
}
.row.compact{ grid-template-columns: 1fr auto; }
label{ color:var(--text); opacity:.9; }
input[type="number"], select, button{
  background: var(--panel-2); color: var(--text);
  border:1px solid var(--card-border); border-radius:10px;
  padding:8px 10px; outline:none;
}
input[type="number"]:focus, select:focus{ border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(31,111,235,.15); }
button{ cursor:pointer; }
button.success{
  background: linear-gradient(180deg, #2ea043, #278a39);
  border-color: #2a8a3e;
}
button:disabled{ opacity:.5; cursor:not-allowed; }

/* Inline controls */
.inline-controls{
  display:grid; grid-template-columns: auto 1fr auto;
  gap:6px; align-items:center; width:190px; max-width:100%;
}
.inline-controls input[type="number"]{ width:100%; text-align:right; }
.inline-controls button{
  min-width:34px; height:34px; padding:0 8px; line-height:1;
  background:#111723; border:1px solid var(--card-border); border-radius:10px;
}
.inline-controls button:hover{ box-shadow:0 0 0 3px rgba(31,111,235,.12); border-color:#2a3650; }
.inline-controls button:active{ transform: translateY(1px); }

/* Toggle (solo móvil) */
.menu-toggle{ display:none; }

/* Dropzone (desktop) */
.dropzone{
  position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:8px; padding:14px; border:1px dashed #2b3340; border-radius:12px; background:#0d131a;
}
.dropzone.hover{ border-color: var(--accent-2); box-shadow: inset 0 0 0 2px rgba(31,111,235,.25); }
.dropzone .dropzone-btn{
  width:100%; padding:10px 12px; border-radius:10px;
  background:#111723; border:1px solid #253044; color:var(--text);
}
.dropzone .hint{ margin:0; color:var(--muted); font-size:12px; text-align:center; }
.dropzone .muted{ color:var(--muted); }
.dropzone input[type="file"]{ position:absolute; inset:0; opacity:0; width:100%; height:100%; cursor:pointer; }

/* Segmentos & stats */
.segments-list{ display:flex; flex-direction:column; gap:8px; max-height:260px; overflow:auto; }
.segments-list.empty{ color:var(--muted); }
.segment{
  display:grid; grid-template-columns:28px 1fr auto; gap:10px; align-items:center;
  background:#0e141c; border:1px solid var(--card-border); border-radius:10px; padding:8px;
}
.segment .swatch{ width:24px; height:24px; border-radius:6px; border:1px solid rgba(255,255,255,.12); }
.segment .name{ font-weight:600; }
.segment small{ color:var(--muted); }
.card.stats .stats-grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.card.stats .metric{ background:#0e141c; border:1px solid var(--card-border); border-radius:10px; padding:8px 10px; }
.card.stats .metric span{ color:var(--muted); font-size:12px; display:block; }
.card.stats .metric strong{ font-size:15px; }

/* Scrollbars */
.sidebar.floating, .segments-list{
  scrollbar-width:thin; scrollbar-color:#273042 #0e141c;
}
.sidebar.floating::-webkit-scrollbar, .segments-list::-webkit-scrollbar{ width:10px; height:10px; }
.sidebar.floating::-webkit-scrollbar-track, .segments-list::-webkit-scrollbar-track{ background:#0e141c; border-radius:10px; }
.sidebar.floating::-webkit-scrollbar-thumb, .segments-list::-webkit-scrollbar-thumb{
  background:#273042; border-radius:10px; border:2px solid #0e141c;
}
.sidebar.floating::-webkit-scrollbar-thumb:hover, .segments-list::-webkit-scrollbar-thumb:hover{ background:#334155; }

/* Grupos de color */
.segment-color{ background:#0e141c; border:1px solid var(--card-border); border-radius:10px; padding:8px; }
.segment-color__header{ display:grid; grid-template-columns:28px 1fr auto; gap:10px; align-items:center; margin-bottom:6px; }
.segment-color__header .swatch{ width:24px; height:24px; border-radius:6px; border:1px solid rgba(255,255,255,.12); }
.segment-color__title{ display:inline-flex; align-items:center; gap:6px; font-weight:600; }
.segment-color__title .disclosure{ background:transparent; border:0; padding:0; margin:0; font:inherit; color:inherit; line-height:1; cursor:pointer; transform:translateY(1px); }
.segment-color__controls{ padding:2px 0 6px; }
.segment-color__items{ display:flex; flex-direction:column; gap:6px; }
.segment-color__items[hidden]{ display:none !important; }

.segment-row{
  display:grid; grid-template-columns:28px 1fr auto; gap:10px; align-items:center;
  background:#0b1118; border:1px solid var(--card-border); border-radius:10px; padding:8px;
}
.segment-row .swatch{ width:24px; height:24px; border-radius:6px; border:1px solid rgba(255,255,255,.12); }
.segment-row .controls .top{ display:flex; justify-content:space-between; gap:10px; margin-bottom:6px; }

/* =============================== MÓVIL =============================== */
@media (max-width: 980px){

  /* Orden explícito de filas: 1 toggle, 2 menú, 3 viewer */
  #app{
    grid-template-columns: 1fr;
    grid-template-rows: auto 0 1fr; /* cerrado: menú no ocupa espacio */
    gap:12px;
    padding:12px;
    min-height: 100svh;
  }
  .menu-toggle{ grid-column:1; grid-row:1; }
  .sidebar.floating{ grid-column:1; grid-row:2; }
  .viewer{ grid-column:1; grid-row:3; }

  /* Toggle compacto */
  .menu-toggle{
    display:inline-flex; align-items:center; gap:8px;
    padding:8px 10px; font-size:14px;
    border:1px solid var(--card-border); border-radius:10px;
    background:#111723; color: var(--text);
    margin:0 0 8px; width:auto; align-self:flex-start;
    transition:filter .2s, transform .06s;
    z-index:3; position:relative;
  }
  .menu-toggle:hover{ filter:brightness(1.07) }
  .menu-toggle:active{ transform:translateY(1px) }

  /* Menú cerrado/abierto
     - Cerrado: oculto visualmente y sin ocupar espacio.
     - Abierto: sin límites → se muestra COMPLETO; la página scrollea si hace falta. */
  .sidebar.floating{
    padding: 0 12px;
    border-width: 0;
    overflow: hidden;
    margin: 0;
    position: relative;
    z-index: 2;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity .18s ease, transform .18s ease, padding .18s ease, border-width .18s ease;
  }
  .sidebar.floating.is-open{
    opacity: 1;
    transform: none;
    padding: 12px;
    border-width: 1px;
    overflow: visible;     /* clave: NADA de scroll interno */
    margin-bottom: 8px;
  }

  /* Cuando el menú está ABIERTO: la fila 2 pasa a auto y el 3D baja */
  #app:has(.sidebar.floating.is-open){
    grid-template-rows: auto auto minmax(55svh, 1fr);
  }

  /* Dropzone: solo botón */
  .dropzone{ padding:0; border:0; background:transparent; gap:0; }
  .dropzone .hint, .dropzone .muted{ display:none; }
  .dropzone input[type="file"]{ position: static; width:1px; height:1px; opacity:0; pointer-events:none; }
  .dropzone .dropzone-btn{ width:100%; padding:10px 12px; }

  /* Viewer */
  .viewer{ height:auto; min-height:0; border-radius:12px; position:relative; z-index:1; }
  #app:has(.sidebar.floating.is-open) .viewer{ height:55svh; }
}

@media (max-width: 600px){
  .inline-controls{ width:170px; }
  .card{ padding:10px; border-radius:12px; }
  .segments-list{ max-height:200px; }
  #app:has(.sidebar.floating.is-open) .viewer{ height:58svh; }
}