:root {
      --bg: #f8fafc; --card: #ffffff; --muted: #6b7280; --text: #111827;
      --primary: #4f46e5; --border: #e5e7eb; --ink: #1f2937;
      --p1: rgba(99,102,241,.22); --p1b: rgba(99,102,241,.6);
      --p2: rgba(16,185,129,.22); --p2b: rgba(16,185,129,.65);
      --alert: #b91c1c; --alertbg:#fee2e2; --alertbd:#fecaca;
    }
    * { box-sizing: border-box; }
    body { margin:0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji"; background: var(--bg); color: var(--text); height: 100vh; }
    h1,h2,h3 { margin: 0 0 .3rem 0; }
    h2 { 
      font-size: 16px; 
      color: #1f2937; 
      font-weight: 600; 
      padding: 6px 0;
      border-bottom: 2px solid rgba(99, 102, 241, 0.1);
      margin-bottom: 12px;
    }
    .wrap { 
      width: 100%; 
      height: 100vh; 
      margin: 0; 
      padding: 8px; 
      display: grid; 
      grid-template-columns: 320px 1fr; 
      gap: 12px; 
      align-items: stretch;
    }
    .card { 
      background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%); 
      border: 1px solid rgba(99, 102, 241, 0.1); 
      border-radius: 14px; 
      box-shadow: 0 4px 20px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.06); 
      padding: 12px; 
      height: 100%; 
      overflow-y: auto;
      transition: all 0.3s ease;
      position: relative;
    }
    .card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 2px;
      background: linear-gradient(90deg, #4f46e5, #7c3aed, #06b6d4);
      border-radius: 16px 16px 0 0;
    }
    .card:hover {
      box-shadow: 0 8px 30px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.08);
      transform: translateY(-2px);
    }
    .section { margin-bottom: 8px; }
    fieldset { 
      border: 2px solid rgba(99, 102, 241, 0.15); 
      border-radius: 10px; 
      padding: 10px; 
      margin: 8px 0;
      min-height: auto;
      background: linear-gradient(135deg, rgba(255,255,255,0.6) 0%, rgba(248,250,252,0.4) 100%);
      box-shadow: 0 2px 8px rgba(0,0,0,.04);
      transition: all 0.2s ease;
    }
    fieldset:hover {
      border-color: rgba(99, 102, 241, 0.25);
      box-shadow: 0 4px 12px rgba(0,0,0,.08);
    }
    fieldset#piece2Block {
      margin-top: 12px;
      border-color: rgba(16, 185, 129, 0.15);
    }
    fieldset#piece2Block:hover {
      border-color: rgba(16, 185, 129, 0.25);
    }
    legend { 
      padding: 2px 8px; 
      color: #4f46e5; 
      font-size: 11px; 
      font-weight: 600;
      background: rgba(79, 70, 229, 0.08);
      border-radius: 12px;
      border: 1px solid rgba(79, 70, 229, 0.2);
      box-shadow: none;
    }
    #piece2Block legend {
      background: rgba(16, 185, 129, 0.08);
      color: #10b981;
      border: 1px solid rgba(16, 185, 129, 0.2);
    }
    legend label {
      cursor: pointer;
      font-weight: normal;
    }
    label { 
      font-size: 11px; 
      color: var(--ink); 
      display:block; 
      margin-bottom:4px; 
      font-weight: 500;
    }
    input[type="number"], select { 
      width: 100%; 
      padding: 6px 8px; 
      border: 2px solid var(--border); 
      border-radius: 6px; 
      font-size: 12px; 
      background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%);
      transition: all 0.2s ease;
      box-shadow: 0 1px 3px rgba(0,0,0,.1);
    }
    input[type="number"]:focus, select:focus {
      outline: none;
      border-color: #4f46e5;
      box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1), 0 1px 3px rgba(0,0,0,.1);
      background: #ffffff;
    }
    input[type="number"]:hover, select:hover {
      border-color: #c7d2fe;
    }
    input[type="checkbox"] { 
      margin-right: 6px; 
      transform: scale(1.1);
    }
    input[type="radio"] { 
      margin-right: 4px; 
    }
    .grid-2 { display:grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .row { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
    .muted { color: var(--muted); font-size: 11px; }
    .result { 
      background:#f3f4f6; 
      border-radius: 8px; 
      padding: 10px; 
      margin-top: 12px;
    }
    .result div { 
      margin-bottom: 4px; 
    }
    .result div:last-child { 
      margin-bottom: 0; 
    }
    .previewCard { 
      display:flex; 
      flex-direction:column; 
      height: 100%; 
      overflow: hidden;
    }
    .previewHead { display:flex; align-items:center; justify-content:space-between; margin-bottom:8px; padding: 0 4px; }
    .previewArea { 
      position:relative; 
      width:100%; 
      flex: 1; 
      overflow:auto; 
      background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
      border-radius: 12px;
      border: 2px solid rgba(99, 102, 241, 0.1);
      box-shadow: inset 0 2px 8px rgba(0,0,0,.04);
    }
    .sheet { position:relative; background:#f5f5f5; border:1px solid #d1d5db; border-radius: 12px; box-shadow: inset 0 1px 2px rgba(0,0,0,.05); }
    .usable { position:absolute; border:2px dashed #9ca3af; border-radius: 8px; }
    .piece { position:absolute; border-radius: 6px; display:flex; align-items:center; justify-content:center; font-size:10px; user-select:none; }
    .piece.p1 { background: var(--p1); border:1px solid var(--p1b); }
    .piece.p2 { background: var(--p2); border:1px solid var(--p2b); }
    .piece .dot { width:8px; height:8px; border-radius:999px; background: rgba(0,0,0,.35); }
    .alert { 
      border:1px solid var(--alertbd); 
      background:var(--alertbg); 
      color:var(--alert); 
      border-radius:8px; 
      padding:8px 10px; 
      font-size:11px; 
      margin-top:6px;
      line-height: 1.3;
    }
    .tips { 
      margin-top: 2px; 
      padding: 6px 10px;
      background: rgba(248, 250, 252, 0.7);
      border: 1px solid rgba(229, 231, 235, 0.8);
      border-radius: 8px;
      position: relative;
    }
    .tips h3 {
      margin: 0 0 3px 0;
      font-size: 11px;
      font-weight: 500;
      color: #6b7280;
    }
    .tips ul {
      margin: 0;
      padding-left: 14px;
    }
    .tips li { 
      margin: 0; 
      font-size: 9px; 
      line-height: 1.1;
    }
    .switch { display:inline-flex; align-items:center; gap:4px; margin-right: 8px; }
    .inline-controls { 
      display:flex; 
      gap:8px; 
      align-items:center; 
      flex-wrap:wrap; 
      margin-top: 8px;
    }
    .inline-controls input[type="number"] {
      width: 80px;
      flex-shrink: 0;
    }
    
    /* Estilos específicos para los fieldsets de piezas */
    #piece2Block {
      border: 2px dashed var(--border);
      background: #fafafa;
    }
    #piece2Block.enabled {
      border: 2px solid var(--primary);
      background: rgba(79,70,229,0.02);
    }

    /* Estilos de las reglas y medidas */
    .ruler-x, .ruler-y { position:absolute; pointer-events:none; font-size:10px; color:#4b5563; }
    .tick-x { position:absolute; border-left:1px solid #9ca3af; height:8px; top:-18px; }
    .tick-x span { position:absolute; top:-12px; left:-10px; }
    .tick-y { position:absolute; border-top:1px solid #9ca3af; width:8px; left:-18px; }
    .tick-y span { position:absolute; left:-22px; top:-8px; }

    /* Responsivo para cuando está en el modal */
    @media (max-width: 640px) {
      .wrap {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: 100vh;
        padding: 4px;
        gap: 8px;
      }
      
      .card {
        height: auto;
        max-height: 40vh;
        overflow-y: auto;
        position: relative;
      }
      

      
      .previewCard {
        height: 60vh;
        display: flex;
        flex-direction: column;
      }
      
      /* Cuando aparecen los resultados, ajustar las proporciones */
      .previewCard.with-results {
        height: 80vh;
        display: flex;
        flex-direction: column;
      }
      
      .previewCard.with-results .previewHead {
        flex-shrink: 0;
      }
      
      .previewCard.with-results #preview {
        flex: 1;
        min-height: 180px;
        max-height: 40vh;
      }
      
      .previewCard.with-results .resultados-imposicion {
        flex: 0 0 auto;
        min-height: 160px;
        max-height: 35vh;
        overflow-y: auto;
        margin-top: 8px;
        padding: 8px;
        font-size: 12px;
      }
      
      /* Ajustes específicos para resultados en móvil */
      .previewCard.with-results .resultados-imposicion h3 {
        font-size: 16px;
        margin-bottom: 10px;
        font-weight: 700;
      }
      
      .previewCard.with-results .resultado-item {
        padding: 10px 0;
        font-size: 13px;
        min-height: 36px;
      }
      
      .previewCard.with-results .resultado-label {
        font-size: 13px;
        font-weight: 500;
      }
      
      .previewCard.with-results .resultado-valor {
        font-size: 15px;
        font-weight: 700;
      }
      
      .previewCard.with-results .resultado-item.destacado .resultado-valor {
        font-size: 17px;
        font-weight: 800;
      }
      
      .previewCard.with-results .btn-utilizar {
        padding: 10px 20px;
        font-size: 13px;
        min-height: 42px;
        font-weight: 700;
      }
      
      /* Arreglar anchos inconsistentes de radio buttons en móvil */
      .inline-controls {
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
        margin-top: 8px;
      }
      
      .inline-controls label.row {
        width: 100%;
        flex: 1;
        justify-content: flex-start;
        padding: 6px 8px;
        background: rgba(255, 255, 255, 0.6);
        border: 1px solid rgba(99, 102, 241, 0.2);
        border-radius: 6px;
        transition: all 0.2s ease;
      }
      
      .inline-controls label.row:hover {
        background: rgba(99, 102, 241, 0.1);
        border-color: rgba(99, 102, 241, 0.3);
      }
      
      .inline-controls input[type="number"] {
        width: 100%;
        margin-top: 8px;
        flex-shrink: 1;
      }
      
      #preview {
        flex: 1;
        height: 100%;
      }
    }

    /* Pantallas grandes - mantener consejos compactos */
    @media (min-width: 641px) {
      .tips { 
        margin-top: 2px; 
        padding: 4px 6px 4px 6px;
        max-height: 65px;
      }
      .tips h3 {
        margin: 0 0 3px 0;
        font-size: 12px;
      }
      .tips ul {
        margin: 0;
        padding-left: 14px;
      }
      .tips li { 
        margin: 0; 
        font-size: 10px; 
        line-height: 1.1;
      }
    }

    /* Estilos para la sección de resultados */
    .resultados-imposicion {
      margin-top: 12px;
      padding: 12px;
      background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
      border: 2px solid rgba(71, 85, 105, 0.2);
      border-radius: 8px;
      box-shadow: 0 2px 8px rgba(71, 85, 105, 0.1);
      color: #1e293b;
    }

    .resultados-imposicion h3 {
      margin: 0 0 12px 0;
      font-size: 15px;
      font-weight: 700;
      color: #0f172a;
      text-align: center;
      padding-bottom: 8px;
      border-bottom: 1px solid rgba(71, 85, 105, 0.2);
    }

    .resultado-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 0;
      border-bottom: 1px solid rgba(71, 85, 105, 0.15);
      min-height: 32px;
    }

    .resultado-item:last-child {
      border-bottom: none;
    }

    .resultado-item.destacado {
      background: rgba(59, 130, 246, 0.1);
      margin: 6px -8px;
      padding: 10px 8px;
      border-radius: 6px;
      font-weight: 700;
      border: 1px solid rgba(59, 130, 246, 0.2);
    }

    .resultado-label {
      font-size: 13px;
      color: #475569;
      font-weight: 500;
    }

    .resultado-valor {
      font-size: 14px;
      font-weight: 700;
      color: #1e293b;
      text-align: right;
    }

    .resultado-item.destacado .resultado-label {
      color: #1e40af;
      font-weight: 600;
    }

    .resultado-item.destacado .resultado-valor {
      color: #1e40af;
      font-size: 16px;
      font-weight: 800;
    }

    .utilizar-container {
      text-align: center;
      margin-top: 16px;
      padding-top: 12px;
      border-top: 2px solid rgba(71, 85, 105, 0.2);
    }

    .btn-utilizar {
      background: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%);
      color: white;
      border: none;
      padding: 12px 28px;
      border-radius: 8px;
      font-size: 14px;
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      box-shadow: 0 3px 12px rgba(124, 58, 237, 0.4);
      min-height: 44px;
    }

    .btn-utilizar:hover {
      background: linear-gradient(135deg, #6d28d9 0%, #5b21b6 100%);
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
    }

    .btn-utilizar:active {
      transform: translateY(0);
    }

    /* Media query para tablets medianas - mantener layout de columnas pero ajustado */
    @media (min-width: 641px) and (max-width: 1024px) {
      .wrap {
        grid-template-columns: 280px 1fr;
        padding: 6px;
        gap: 10px;
      }
      
      .card {
        padding: 12px;
      }
      
      fieldset {
        padding: 8px;
        margin: 6px 0;
      }
      
      h2 {
        font-size: 14px;
      }
      
      label {
        font-size: 10px;
      }
      
      input, select {
        padding: 5px 6px;
        font-size: 11px;
      }
    }
    
    /* Indicador de scroll para configuración - disponible globalmente */
    .scroll-indicator {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: rgba(79, 70, 229, 0.95);
      color: white;
      padding: 8px 16px;
      border-radius: 25px;
      font-size: 12px;
      font-weight: 700;
      white-space: nowrap;
      z-index: 1000;
      box-shadow: 0 4px 12px rgba(0,0,0,0.3);
      animation: scrollHint 1.5s ease-in-out infinite;
      pointer-events: none;
      border: 2px solid rgba(255,255,255,0.3);
      display: none;
    }
    
    /* Solo mostrar en móvil cuando hay scroll */
    @media (max-width: 640px) {
      .scroll-indicator.show {
        display: block;
      }
    }
    
    /* Animación para el indicador de scroll */
    @keyframes scrollHint {
      0%, 100% {
        transform: translate(-50%, -50%) translateY(0);
        opacity: 0.8;
      }
      50% {
        transform: translate(-50%, -50%) translateY(-3px);
        opacity: 1;
      }
    }